-
Notifications
You must be signed in to change notification settings - Fork 727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
map: unmarshaling silently ignores too small keys or values #1157
Comments
I can reproduced this.
nextKeyOut has no explicit type.
@ti-mo |
I'll see whether this was introduced by #1062. P.S. Doesn't seem to be caused by the marshaling changes. diff --git a/map_test.go b/map_test.go
index 2d3e4add..6d50e685 100644
--- a/map_test.go
+++ b/map_test.go
@@ -227,6 +227,36 @@ func TestBatchAPIHash(t *testing.T) {
}
}
+func TestBatchLookupKeyTooSmall(t *testing.T) {
+ m, err := NewMap(&MapSpec{
+ Type: LRUHash,
+ KeySize: 8,
+ ValueSize: 8,
+ MaxEntries: 10,
+ })
+ qt.Assert(t, err, qt.IsNil)
+ defer m.Close()
+
+ keys, values := make([]uint64, m.MaxEntries()), make([]uint64, m.MaxEntries())
+ for i := 0; uint32(i) < m.MaxEntries(); i++ {
+ keys[i] = uint64(i)
+ values[i] = uint64(i)
+ }
+
+ count, err := m.BatchUpdate(keys, values, nil)
+ qt.Assert(t, err, qt.IsNil)
+ t.Log("wrote", count, "entries")
+
+ // Undersized nextKey. Only uint64 should be accepted here. (KeySize 8)
+ // Should contain 1048576 at the end of program. uint32 works as well, as it
+ // can represent up to 4.2B.
+ var nextKey uint16
+
+ keysOut, valuesOut := make([]uint64, m.MaxEntries()), make([]uint64, m.MaxEntries())
+ _, err = m.BatchLookup(nil, &nextKey, keysOut, valuesOut, nil)
+ qt.Assert(t, err, qt.IsNotNil)
+}
+
func TestBatchAPIMapDelete(t *testing.T) {
if err := haveBatchAPI(); err != nil {
t.Skipf("batch api not available: %v", err)
|
The problem is here somewhere most likely: Lines 985 to 993 in 9598c01
|
This is actually not batch specific, it applies to all unmarshaling from map values. |
Unmarshal currently doesn't check that unmarshaling actually consumes to full buffer. This means that looking uint16 from an uint32 value doesn't return an error. Fixes cilium#1157 Signed-off-by: Lorenz Bauer <[email protected]>
Unmarshal currently doesn't check that unmarshaling actually consumes to full buffer. This means that looking uint16 from an uint32 value doesn't return an error. Fixes cilium#1157 Signed-off-by: Lorenz Bauer <[email protected]>
Unmarshal currently doesn't check that unmarshaling actually consumes to full buffer. This means that looking uint16 from an uint32 value doesn't return an error. Fixes cilium#1157 Signed-off-by: Lorenz Bauer <[email protected]>
Unmarshal currently doesn't check that unmarshaling actually consumes to full buffer. This means that looking uint16 from an uint32 value doesn't return an error. Fixes #1157 Signed-off-by: Lorenz Bauer <[email protected]>
Describe the bug
Map.BatchLookup fails silently if nextKey is undersized, leaving nextKey with a zero value.
To Reproduce
Expected behavior
BatchLookup should fail with an unmarshaling error.
The text was updated successfully, but these errors were encountered: