Skip to content

Commit 8fca0a1

Browse files
committed
Check that --ip-range is a CIDR address
Signed-off-by: Rob Murray <rob.murray@docker.com>
1 parent daabb15 commit 8fca0a1

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

cli/command/network/create.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ func createIPAMConfig(options ipamOptions) (*network.IPAM, error) {
163163
for _, r := range options.ipRanges {
164164
match := false
165165
for _, s := range options.subnets {
166+
if _, _, err := net.ParseCIDR(r); err != nil {
167+
return nil, err
168+
}
166169
ok, err := subnetMatches(s, r)
167170
if err != nil {
168171
return nil, err

cli/command/network/create_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ func TestNetworkCreateErrors(t *testing.T) {
124124
},
125125
expectedError: "no matching subnet for aux-address",
126126
},
127+
{
128+
args: []string{"toto"},
129+
flags: map[string]string{
130+
"ip-range": "192.168.83.1-192.168.83.254",
131+
"gateway": "192.168.80.1",
132+
"subnet": "192.168.80.0/20",
133+
},
134+
expectedError: "invalid CIDR address: 192.168.83.1-192.168.83.254",
135+
},
127136
}
128137

129138
for _, tc := range testCases {

0 commit comments

Comments
 (0)