Merge pull request #5483 from robmry/ip-range-validation

Check that --ip-range is a CIDR address
This commit is contained in:
Sebastiaan van Stijn 2024-09-26 22:49:12 +02:00 committed by GitHub
commit c767b9b2da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -163,6 +163,9 @@ func createIPAMConfig(options ipamOptions) (*network.IPAM, error) {
for _, r := range options.ipRanges { for _, r := range options.ipRanges {
match := false match := false
for _, s := range options.subnets { for _, s := range options.subnets {
if _, _, err := net.ParseCIDR(r); err != nil {
return nil, err
}
ok, err := subnetMatches(s, r) ok, err := subnetMatches(s, r)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -124,6 +124,15 @@ func TestNetworkCreateErrors(t *testing.T) {
}, },
expectedError: "no matching subnet for aux-address", 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 { for _, tc := range testCases {