Skip to content

Commit

Permalink
Relieve length check for NeighAttributes (#208)
Browse files Browse the repository at this point in the history
* Remove length check for NeighAttributes

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.

This completely removes any length check for neighbor attributes.
This places the burden of checking for correctness to the consumer
of this library.
  • Loading branch information
jsimonetti authored Jan 25, 2024
1 parent 8740a9c commit 8f6dc23
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 24 deletions.
10 changes: 0 additions & 10 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 @@ -185,10 +182,6 @@ func (a *NeighAttributes) decode(ad *netlink.AttributeDecoder) error {
case unix.NDA_UNSPEC:
// unused attribute
case unix.NDA_DST:
l := len(ad.Bytes())
if l != 4 && l != 16 {
return errInvalidNeighMessageAttr
}
a.Address = ad.Bytes()
case unix.NDA_LLADDR:
// Allow IEEE 802 MAC-48, EUI-48, EUI-64, or 20-octet
Expand All @@ -198,9 +191,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 8f6dc23

Please sign in to comment.