diff options
author | Pablo Mazzini <pmazzini@gmail.com> | 2018-07-14 20:31:12 +0200 |
---|---|---|
committer | Pablo Mazzini <pmazzini@gmail.com> | 2018-07-14 20:31:12 +0200 |
commit | ae64b38d35aaa4ff0cc58ab617b0cb367389fb5d (patch) | |
tree | 7c0ced67ba848e46be222b3c28580114d094f9ed /dhcpv6 | |
parent | 2ae16808e62447f746632531328742403c487b36 (diff) |
return error if index < -1
Diffstat (limited to 'dhcpv6')
-rw-r--r-- | dhcpv6/dhcpv6.go | 4 | ||||
-rw-r--r-- | dhcpv6/dhcpv6_test.go | 3 |
2 files changed, 6 insertions, 1 deletions
diff --git a/dhcpv6/dhcpv6.go b/dhcpv6/dhcpv6.go index c9e42e2..b424101 100644 --- a/dhcpv6/dhcpv6.go +++ b/dhcpv6/dhcpv6.go @@ -153,7 +153,9 @@ func DecapsulateRelayIndex(l DHCPv6, index int) (DHCPv6, error) { if !l.IsRelay() { return l, nil } - if index == -1 { + if index < -1 { + return nil, fmt.Errorf("Invalid index: %d", index) + } else if index == -1 { for { d, err := DecapsulateRelay(l) if err != nil { diff --git a/dhcpv6/dhcpv6_test.go b/dhcpv6/dhcpv6_test.go index 6b7d2df..2db5649 100644 --- a/dhcpv6/dhcpv6_test.go +++ b/dhcpv6/dhcpv6_test.go @@ -74,6 +74,9 @@ func TestDecapsulateRelayIndex(t *testing.T) { require.Equal(t, relay.HopCount(), uint8(0)) require.Equal(t, relay.LinkAddr(), net.IPv6linklocalallnodes) require.Equal(t, relay.PeerAddr(), net.IPv6interfacelocalallnodes) + + _, err = DecapsulateRelayIndex(r3, -2) + require.Error(t, err) } func TestSettersAndGetters(t *testing.T) { |