diff options
author | Anatole Denis <natolumin@unverle.fr> | 2019-10-03 20:59:14 +0200 |
---|---|---|
committer | Anatole Denis <natolumin@unverle.fr> | 2019-10-08 08:56:49 +0200 |
commit | 1d9062326df943510ecaff2be53bd630a419b684 (patch) | |
tree | 76c36e045a9c17a6e078783e2f795d3b6ce08385 /dhcpv6/dhcpv6.go | |
parent | 1c72f431b01aa49492752868c3e3c5ad7a6a3d84 (diff) |
dhcpv6: Add error checks to message parsers
There were missing error checks in the Message and RelayMessage parsers,
so that truncated headers would be incorrectly accepted as valid
messages. For example the single byte "0" (0x30) would be accepted as a
valid message, then reserialized to 0x30,0x00,0x00,0x00,0x00
Signed-off-by: Anatole Denis <natolumin@unverle.fr>
Diffstat (limited to 'dhcpv6/dhcpv6.go')
-rw-r--r-- | dhcpv6/dhcpv6.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/dhcpv6/dhcpv6.go b/dhcpv6/dhcpv6.go index 576293d..4f7fbbb 100644 --- a/dhcpv6/dhcpv6.go +++ b/dhcpv6/dhcpv6.go @@ -46,6 +46,9 @@ func MessageFromBytes(data []byte) (*Message, error) { MessageType: messageType, } buf.ReadBytes(d.TransactionID[:]) + if buf.Error() != nil { + return nil, fmt.Errorf("Error parsing DHCPv6 header: %v", buf.Error()) + } if err := d.Options.FromBytes(buf.Data()); err != nil { return nil, err } @@ -68,6 +71,9 @@ func RelayMessageFromBytes(data []byte) (*RelayMessage, error) { d.LinkAddr = net.IP(buf.CopyN(net.IPv6len)) d.PeerAddr = net.IP(buf.CopyN(net.IPv6len)) + if buf.Error() != nil { + return nil, fmt.Errorf("Error parsing RelayMessage header: %v", buf.Error()) + } // TODO: fail if no OptRelayMessage is present. if err := d.Options.FromBytes(buf.Data()); err != nil { return nil, err |