From 7dbdd698ae7f364bdd2377a8a0e8828f0714d387 Mon Sep 17 00:00:00 2001 From: Jeroen Simonetti Date: Thu, 28 Dec 2023 18:35:27 +0100 Subject: [PATCH] Releive 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. Signed-off-by: Jeroen Simonetti --- neigh.go | 10 ++-------- neigh_test.go | 14 -------------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/neigh.go b/neigh.go index 22b9f83..2ea824f 100644 --- a/neigh.go +++ b/neigh.go @@ -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{} @@ -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: @@ -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{} diff --git a/neigh_test.go b/neigh_test.go index 2a132f2..8f5b22b 100644 --- a/neigh_test.go +++ b/neigh_test.go @@ -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{