Skip to content
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

sysenc: refuse to unmarshal into undersized dst #1181

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion internal/sysenc/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ func Unmarshal(data interface{}, buf []byte) error {

rd.Reset(buf)

return binary.Read(rd, internal.NativeEndian, value)
if err := binary.Read(rd, internal.NativeEndian, value); err != nil {
return err
}

if rd.Len() != 0 {
return fmt.Errorf("unmarshaling %T doesn't consume all data", data)
}

return nil
}
}

Expand Down
13 changes: 11 additions & 2 deletions map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ func TestBatchAPIHash(t *testing.T) {
}
}

func TestMapLookupKeyTooSmall(t *testing.T) {
m := createArray(t)
defer m.Close()

var small uint16
qt.Assert(t, m.Put(uint32(0), uint32(1234)), qt.IsNil)
qt.Assert(t, m.Lookup(uint32(0), &small), qt.IsNotNil)
}

func TestBatchAPIMapDelete(t *testing.T) {
if err := haveBatchAPI(); err != nil {
t.Skipf("batch api not available: %v", err)
Expand Down Expand Up @@ -1014,7 +1023,7 @@ func TestIterateEmptyMap(t *testing.T) {
entries := m.Iterate()

var key string
var value uint32
var value uint64
if entries.Next(&key, &value) != false {
t.Error("Empty hash should not be iterable")
}
Expand All @@ -1032,7 +1041,7 @@ func TestIterateEmptyMap(t *testing.T) {
m := makeMap(t, mapType)
entries := m.Iterate()
var key string
var value uint32
var value uint64
for entries.Next(&key, &value) {
// Some empty arrays like sockmap don't return any keys.
}
Expand Down