summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4
diff options
context:
space:
mode:
authorPablo Mazzini <pmazzini@gmail.com>2018-08-21 23:04:55 +0100
committerinsomniac <insomniacslk@users.noreply.github.com>2018-08-21 23:04:55 +0100
commitb54e51afcac769dfd51a0df3ec5f73fc390de1a3 (patch)
treee68e121c1ea62f4a3860fa851fcf6da144ea2954 /dhcpv4
parent8a82f8dbe600ba1d30c2c57bd2460cac48efbbef (diff)
fix ParseOptVIVC (#146)
Diffstat (limited to 'dhcpv4')
-rw-r--r--dhcpv4/option_vivc.go6
-rw-r--r--dhcpv4/option_vivc_test.go7
2 files changed, 10 insertions, 3 deletions
diff --git a/dhcpv4/option_vivc.go b/dhcpv4/option_vivc.go
index 9be8557..7576637 100644
--- a/dhcpv4/option_vivc.go
+++ b/dhcpv4/option_vivc.go
@@ -30,12 +30,12 @@ func ParseOptVIVC(data []byte) (*OptVIVC, error) {
if code != OptionVendorIdentifyingVendorClass {
return nil, fmt.Errorf("expected code %v, got %v", OptionVendorIdentifyingVendorClass, code)
}
- length := int(data[1])
- data = data[2:]
- if length != len(data) {
+ length := int(data[1])
+ if len(data) < 2+length {
return nil, ErrShortByteStream
}
+ data = data[2:length+2]
ids := []VIVCIdentifier{}
for len(data) > 5 {
diff --git a/dhcpv4/option_vivc_test.go b/dhcpv4/option_vivc_test.go
index 14ded61..b290da0 100644
--- a/dhcpv4/option_vivc_test.go
+++ b/dhcpv4/option_vivc_test.go
@@ -56,6 +56,13 @@ func TestParseOptVICO(t *testing.T) {
data[6] = 40
_, err = ParseOptVIVC(data)
require.Error(t, err, "should get error from bad length")
+
+ // Longer than length
+ data[1] = 10
+ data[6] = 5
+ o, err = ParseOptVIVC(data)
+ require.NoError(t, err)
+ require.Equal(t, o.Identifiers[0].Data, []byte("Cisco"))
}
func TestOptVIVCString(t *testing.T) {