From b95caade3eac806fa0f09a38d2ca991cf449b7b3 Mon Sep 17 00:00:00 2001 From: Hariharakumar Narasimhakumar Date: Fri, 27 Aug 2021 10:34:40 -0700 Subject: [ztpv4][cisco firepower] Check to ensure serial number in Opt 61 is not empty (#444) * Adding check for empty serial number in opt 61 --- dhcpv4/ztpv4/ztp.go | 3 +++ dhcpv4/ztpv4/ztp_test.go | 1 + 2 files changed, 4 insertions(+) diff --git a/dhcpv4/ztpv4/ztp.go b/dhcpv4/ztpv4/ztp.go index 09ec790..ef8e13d 100644 --- a/dhcpv4/ztpv4/ztp.go +++ b/dhcpv4/ztpv4/ztp.go @@ -72,6 +72,9 @@ func parseClassIdentifier(packet *dhcpv4.DHCPv4) (*VendorData, error) { vd.VendorName = iana.EntIDCiscoSystems.String() vd.Model = vc vd.Serial = dhcpv4.GetString(dhcpv4.OptionClientIdentifier, packet.Options) + if len(vd.Serial) == 0 { + return nil, errors.New("client identifier option is missing") + } return vd, nil } diff --git a/dhcpv4/ztpv4/ztp_test.go b/dhcpv4/ztpv4/ztp_test.go index a6781a1..189ed3b 100644 --- a/dhcpv4/ztpv4/ztp_test.go +++ b/dhcpv4/ztpv4/ztp_test.go @@ -52,6 +52,7 @@ func TestParseClassIdentifier(t *testing.T) { ci: []byte("JMX2525X0BW"), want: &VendorData{VendorName: "Cisco Systems", Model: "FPR4100", Serial: "JMX2525X0BW"}, }, + {name: "ciscoNoSerial", vc: "FPR4100", fail: true}, } for _, tc := range tt { -- cgit v1.2.3