From 4502285c06f712f419ca9f30fb84283bcdb01d62 Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Wed, 15 Aug 2018 14:07:40 +0100 Subject: stop parsing after end (#132) --- dhcpv4/options.go | 3 +++ dhcpv4/options_test.go | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'dhcpv4') diff --git a/dhcpv4/options.go b/dhcpv4/options.go index d869b7d..02fa6e4 100644 --- a/dhcpv4/options.go +++ b/dhcpv4/options.go @@ -126,6 +126,9 @@ func OptionsFromBytesWithoutMagicCookie(data []byte) ([]Option, error) { return nil, err } options = append(options, opt) + if opt.Code() == OptionEnd { + break + } // Options with zero length have no length byte, so here we handle the // ones with nonzero length diff --git a/dhcpv4/options_test.go b/dhcpv4/options_test.go index 0268483..899fb2c 100644 --- a/dhcpv4/options_test.go +++ b/dhcpv4/options_test.go @@ -167,12 +167,9 @@ func TestOptionsFromBytes(t *testing.T) { } opts, err := OptionsFromBytes(options) require.NoError(t, err) - require.Equal(t, 5, len(opts)) + require.Equal(t, 2, len(opts)) require.Equal(t, opts[0].(*OptionGeneric), &OptionGeneric{OptionCode: OptionNameServer, Data: []byte{192, 168, 1, 1}}) require.Equal(t, opts[1].(*OptionGeneric), &OptionGeneric{OptionCode: OptionEnd}) - require.Equal(t, opts[2].(*OptionGeneric), &OptionGeneric{OptionCode: OptionPad}) - require.Equal(t, opts[3].(*OptionGeneric), &OptionGeneric{OptionCode: OptionPad}) - require.Equal(t, opts[4].(*OptionGeneric), &OptionGeneric{OptionCode: OptionPad}) } func TestOptionsFromBytesZeroLength(t *testing.T) { -- cgit v1.2.3