mirror of
https://github.com/jsimonetti/rtnetlink.git
synced 2026-04-16 01:32:06 +02:00
fix: loosen LinkAttribute length checks (#8)
Loosen the LinkAttribute length checks, to parse links that store information other than MAC addresses in the Address or Broadcast fields. This change, for example, now allows IPIP, GRE over IP, 6to4, and IP over Infiniband. The fields continue to be net.HardwareAddr, which may result in slightly unusual representations when printed as a string. This type can be cast to other byte slice types by users, if necessary. Fix: #7
This commit is contained in:
parent
f719cfd1d2
commit
3629fb389e
6
link.go
6
link.go
@ -217,12 +217,14 @@ func (a *LinkAttributes) UnmarshalBinary(b []byte) error {
|
||||
case iflaUnspec:
|
||||
//unused attribute
|
||||
case iflaAddress:
|
||||
if len(attr.Data) != 6 {
|
||||
l := len(attr.Data)
|
||||
if l < 4 || l > 32 {
|
||||
return errInvalidLinkMessageAttr
|
||||
}
|
||||
a.Address = attr.Data
|
||||
case iflaBroadcast:
|
||||
if len(attr.Data) != 6 {
|
||||
l := len(attr.Data)
|
||||
if l < 4 || l > 32 {
|
||||
return errInvalidLinkMessageAttr
|
||||
}
|
||||
a.Broadcast = attr.Data
|
||||
|
||||
44
link_test.go
44
link_test.go
@ -69,6 +69,28 @@ func TestLinkMessageMarshalBinary(t *testing.T) {
|
||||
0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "attributes ipip",
|
||||
m: &LinkMessage{
|
||||
Attributes: LinkAttributes{
|
||||
Address: []byte{10, 0, 0, 1},
|
||||
Broadcast: []byte{255, 255, 255, 255},
|
||||
Name: "ipip",
|
||||
},
|
||||
},
|
||||
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,
|
||||
0x08, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x00, 0x01,
|
||||
0x08, 0x00, 0x02, 0x00, 0xff, 0xff, 0xff, 0xff,
|
||||
0x09, 0x00, 0x03, 0x00, 0x69, 0x70, 0x69, 0x70,
|
||||
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,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@ -188,6 +210,28 @@ func TestLinkMessageUnmarshalBinary(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "attributes ipip",
|
||||
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,
|
||||
0x08, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x00, 0x01,
|
||||
0x08, 0x00, 0x02, 0x00, 0xff, 0xff, 0xff, 0xff,
|
||||
0x09, 0x00, 0x03, 0x00, 0x69, 0x70, 0x69, 0x70,
|
||||
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,
|
||||
},
|
||||
m: &LinkMessage{
|
||||
Attributes: LinkAttributes{
|
||||
Address: []byte{10, 0, 0, 1},
|
||||
Broadcast: []byte{255, 255, 255, 255},
|
||||
Name: "ipip",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user