Skip to content

Commit

Permalink
Releive length check for NeighAttributes
Browse files Browse the repository at this point in the history
The attribute length has more context then previously presumed.
Especially when using tunnels and other link types, the attributes
can use different lengths then expected.

Signed-off-by: Jeroen Simonetti <[email protected]>
  • Loading branch information
jsimonetti committed Dec 28, 2023
1 parent dbce757 commit 7dbdd69
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
10 changes: 2 additions & 8 deletions neigh.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import (
var (
// errInvalidNeighMessage is returned when a LinkMessage is malformed.
errInvalidNeighMessage = errors.New("rtnetlink NeighMessage is invalid or too short")

// errInvalidNeighMessageAttr is returned when neigh attributes are malformed.
errInvalidNeighMessageAttr = errors.New("rtnetlink NeighMessage has a wrong attribute data length")
)

var _ Message = &NeighMessage{}
Expand Down Expand Up @@ -186,8 +183,8 @@ func (a *NeighAttributes) decode(ad *netlink.AttributeDecoder) error {
// unused attribute
case unix.NDA_DST:
l := len(ad.Bytes())
if l != 4 && l != 16 {
return errInvalidNeighMessageAttr
if l == 0 {
continue
}
a.Address = ad.Bytes()
case unix.NDA_LLADDR:
Expand All @@ -198,9 +195,6 @@ func (a *NeighAttributes) decode(ad *netlink.AttributeDecoder) error {
// Ignore empty addresses.
continue
}
if l != 6 && l != 8 && l != 20 {
return errInvalidNeighMessageAttr
}
a.LLAddress = ad.Bytes()
case unix.NDA_CACHEINFO:
a.CacheInfo = &NeighCacheInfo{}
Expand Down
14 changes: 0 additions & 14 deletions neigh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,6 @@ func TestNeighMessageUnmarshalBinary(t *testing.T) {
b: make([]byte, 11),
err: errInvalidNeighMessage,
},
{
name: "invalid attr",
b: []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x01, 0x00, 0x04, 0x00, 0x02, 0x00,
0x05, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
},
err: errInvalidNeighMessageAttr,
},
{
name: "data",
b: []byte{
Expand Down

0 comments on commit 7dbdd69

Please sign in to comment.