summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Karlage <skarlage@fb.com>2018-08-15 10:20:05 -0700
committerSean Karlage <skarlage@fb.com>2018-08-15 10:20:05 -0700
commitd614fa996b8fb38528191fe52c258037ae9c539a (patch)
treedaa404faab307d019d3222ab62bb17390e59e43a
parent3a9b7911aa8d69f16a3d11bdaf2dc757470192d0 (diff)
Add nil check for Images slice
-rw-r--r--dhcpv4/bsdp/bsdp.go4
-rw-r--r--dhcpv4/bsdp/bsdp_test.go11
2 files changed, 13 insertions, 2 deletions
diff --git a/dhcpv4/bsdp/bsdp.go b/dhcpv4/bsdp/bsdp.go
index 2909ccd..3402b0c 100644
--- a/dhcpv4/bsdp/bsdp.go
+++ b/dhcpv4/bsdp/bsdp.go
@@ -160,7 +160,7 @@ func NewReplyForInformList(inform *dhcpv4.DHCPv4, config ReplyConfig) (*dhcpv4.D
if config.DefaultImage == nil {
return nil, errors.New("NewReplyForInformList: no default boot image ID set")
}
- if len(config.Images) == 0 {
+ if config.Images == nil || len(config.Images) == 0 {
return nil, errors.New("NewReplyForInformList: no boot images provided")
}
reply, err := dhcpv4.NewReplyFromRequest(inform)
@@ -199,7 +199,7 @@ func NewReplyForInformSelect(inform *dhcpv4.DHCPv4, config ReplyConfig) (*dhcpv4
if config.SelectedImage == nil {
return nil, errors.New("NewReplyForInformSelect: no selected boot image ID set")
}
- if len(config.Images) == 0 {
+ if config.Images == nil || len(config.Images) == 0 {
return nil, errors.New("NewReplyForInformSelect: no boot images provided")
}
reply, err := dhcpv4.NewReplyFromRequest(inform)
diff --git a/dhcpv4/bsdp/bsdp_test.go b/dhcpv4/bsdp/bsdp_test.go
index f457631..fc1aedf 100644
--- a/dhcpv4/bsdp/bsdp_test.go
+++ b/dhcpv4/bsdp/bsdp_test.go
@@ -80,6 +80,11 @@ func TestNewReplyForInformList_NoImages(t *testing.T) {
DefaultImage: &fakeImage,
})
require.Error(t, err)
+
+ _, err = NewReplyForInformList(inform, ReplyConfig{
+ Images: nil,
+ SelectedImage: &fakeImage,
+ })
}
// TODO (get9): clean up when #99 lands.
@@ -186,6 +191,12 @@ func TestNewReplyForInformSelect_NoImages(t *testing.T) {
SelectedImage: &fakeImage,
})
require.Error(t, err)
+
+ _, err = NewReplyForInformSelect(inform, ReplyConfig{
+ Images: nil,
+ SelectedImage: &fakeImage,
+ })
+ require.Error(t, err)
}
func TestNewReplyForInformSelect(t *testing.T) {