summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAnatole Denis <natolumin@unverle.fr>2019-10-03 22:51:19 +0200
committerAnatole Denis <natolumin@unverle.fr>2019-10-08 08:56:49 +0200
commit2943f69fe4277297a362c156611e9ccc712e834b (patch)
tree69405fbefbda5374451c6a5090a621009b69d025
parent1d9062326df943510ecaff2be53bd630a419b684 (diff)
iana: HWType is 16 bits
In both ARP and DHCPv6, the hwtype field is 16bits, and the IANA table has allocated values >255. (Bootp however uses 1byte so it can't represent everything) This was discovered by fuzzing, as it causes round-trip mismatches; eg with this packet (quoted string): "0000\x00\x01\x00\x0e\x00\x01000000000000" Input: 303030300001000e0001303030303030303030303030 Round-trip: 303030300001000e0001003030303030303030303030 ^ The upper byte of the hwaddress is set to 0 Signed-off-by: Anatole Denis <natolumin@unverle.fr>
-rw-r--r--dhcpv6/dhcpv6_test.go18
-rw-r--r--iana/hwtypes.go2
2 files changed, 14 insertions, 6 deletions
diff --git a/dhcpv6/dhcpv6_test.go b/dhcpv6/dhcpv6_test.go
index 844dabf..d097095 100644
--- a/dhcpv6/dhcpv6_test.go
+++ b/dhcpv6/dhcpv6_test.go
@@ -130,11 +130,19 @@ func TestToBytes(t *testing.T) {
}
func TestFromAndToBytes(t *testing.T) {
- expected := []byte{01, 0xab, 0xcd, 0xef, 0x00, 0x00, 0x00, 0x00}
- d, err := FromBytes(expected)
- require.NoError(t, err)
- toBytes := d.ToBytes()
- require.Equal(t, expected, toBytes)
+ expected := [][]byte{
+ {01, 0xab, 0xcd, 0xef, 0x00, 0x00, 0x00, 0x00},
+ []byte("0000\x00\x01\x00\x0e\x00\x01000000000000"),
+ }
+ t.Parallel()
+ for i, packet := range expected {
+ t.Run(strconv.Itoa(i), func(t *testing.T) {
+ d, err := FromBytes(packet)
+ require.NoError(t, err)
+ toBytes := d.ToBytes()
+ require.Equal(t, packet, toBytes)
+ })
+ }
}
func TestFromBytesInvalid(t *testing.T) {
diff --git a/iana/hwtypes.go b/iana/hwtypes.go
index bbb3188..e6fb38b 100644
--- a/iana/hwtypes.go
+++ b/iana/hwtypes.go
@@ -1,7 +1,7 @@
package iana
// HWType is a hardware type as per RFC 2132 and defined by the IANA.
-type HWType uint8
+type HWType uint16
// See IANA for values.
const (