From 8fca0a1f289f18c5a8f274b39b41fecf8c5e2100 Mon Sep 17 00:00:00 2001 From: Rob Murray Date: Thu, 26 Sep 2024 20:21:10 +0100 Subject: [PATCH] Check that --ip-range is a CIDR address Signed-off-by: Rob Murray --- cli/command/network/create.go | 3 +++ cli/command/network/create_test.go | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/cli/command/network/create.go b/cli/command/network/create.go index 436cea34f9db..69374c5880e4 100644 --- a/cli/command/network/create.go +++ b/cli/command/network/create.go @@ -163,6 +163,9 @@ func createIPAMConfig(options ipamOptions) (*network.IPAM, error) { for _, r := range options.ipRanges { match := false for _, s := range options.subnets { + if _, _, err := net.ParseCIDR(r); err != nil { + return nil, err + } ok, err := subnetMatches(s, r) if err != nil { return nil, err diff --git a/cli/command/network/create_test.go b/cli/command/network/create_test.go index 348835f02ab4..94ff0ffc97bf 100644 --- a/cli/command/network/create_test.go +++ b/cli/command/network/create_test.go @@ -124,6 +124,15 @@ func TestNetworkCreateErrors(t *testing.T) { }, expectedError: "no matching subnet for aux-address", }, + { + args: []string{"toto"}, + flags: map[string]string{ + "ip-range": "192.168.83.1-192.168.83.254", + "gateway": "192.168.80.1", + "subnet": "192.168.80.0/20", + }, + expectedError: "invalid CIDR address: 192.168.83.1-192.168.83.254", + }, } for _, tc := range testCases {