From ae64b38d35aaa4ff0cc58ab617b0cb367389fb5d Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Sat, 14 Jul 2018 20:31:12 +0200 Subject: return error if index < -1 --- dhcpv6/dhcpv6.go | 4 +++- dhcpv6/dhcpv6_test.go | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) 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) { -- cgit v1.2.3