diff options
author | David Barr <38654497+davebarrau@users.noreply.github.com> | 2018-10-09 23:30:20 +1100 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2018-10-09 08:49:43 -0700 |
commit | ee671d361777cc640550bab38cc6b0d412396f80 (patch) | |
tree | 8296bebb4f3c9f2d852a7d3a7a38b4c2e86c1f50 | |
parent | d9c0ac3ffae38b8c7b8d6ccee1f4041ecdbc6c34 (diff) |
Avoid panic on malformed OptIAPrefix
-rw-r--r-- | dhcpv6/option_iaprefix.go | 4 | ||||
-rw-r--r-- | dhcpv6/option_iaprefix_test.go | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/dhcpv6/option_iaprefix.go b/dhcpv6/option_iaprefix.go index 3f6227b..1f68789 100644 --- a/dhcpv6/option_iaprefix.go +++ b/dhcpv6/option_iaprefix.go @@ -86,8 +86,8 @@ func (op *OptIAPrefix) String() string { // The input data does not include option code and length bytes. func ParseOptIAPrefix(data []byte) (*OptIAPrefix, error) { opt := OptIAPrefix{} - if len(data) < 12 { - return nil, fmt.Errorf("Invalid IA for Prefix Delegation data length. Expected at least 12 bytes, got %v", len(data)) + if len(data) < 25 { + return nil, fmt.Errorf("Invalid IA for Prefix Delegation data length. Expected at least 25 bytes, got %v", len(data)) } opt.preferredLifetime = binary.BigEndian.Uint32(data[:4]) opt.validLifetime = binary.BigEndian.Uint32(data[4:8]) diff --git a/dhcpv6/option_iaprefix_test.go b/dhcpv6/option_iaprefix_test.go index caabc75..0f37214 100644 --- a/dhcpv6/option_iaprefix_test.go +++ b/dhcpv6/option_iaprefix_test.go @@ -50,3 +50,15 @@ func TestOptIAPrefixToBytes(t *testing.T) { t.Fatalf("Invalid ToBytes result. Expected %v, got %v", expected, toBytes) } } + +func TestOptIAPrefixParseInvalidTooShort(t *testing.T) { + buf := []byte{ + 0xaa, 0xbb, 0xcc, 0xdd, // preferredLifetime + 0xee, 0xff, 0x00, 0x11, // validLifetime + 36, // prefixLength + 0, 0, 0, 0, 0, 0, 0, // truncated ipv6Prefix + } + if opt, err := ParseOptIAPrefix(buf); err == nil { + t.Fatalf("ParseOptIAPrefix: Expected error on truncated option, got %v", opt) + } +} |