diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-08-12 10:29:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-12 10:29:17 -0400 |
commit | ac96112d706ac7be682a6a3e218b10affd2ece20 (patch) | |
tree | 3d8cbe927cc6cdc0eaa7412df8edf725b911bc71 /pkg | |
parent | 8eaacec150df782c291e9c6046bb0db010dd2f08 (diff) | |
parent | d45bd6e29ab16b9811dfb2e520a49ed7baebda98 (diff) | |
download | podman-ac96112d706ac7be682a6a3e218b10affd2ece20.tar.gz podman-ac96112d706ac7be682a6a3e218b10affd2ece20.tar.bz2 podman-ac96112d706ac7be682a6a3e218b10affd2ece20.zip |
Merge pull request #7267 from zhangguanzhang/check-invalid-network-create
Add parameter verification for api creation network
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/network/network.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/pkg/network/network.go b/pkg/network/network.go index b24c72f5f..db625da56 100644 --- a/pkg/network/network.go +++ b/pkg/network/network.go @@ -137,6 +137,15 @@ func networkIntersect(n1, n2 *net.IPNet) bool { // ValidateUserNetworkIsAvailable returns via an error if a network is available // to be used func ValidateUserNetworkIsAvailable(config *config.Config, userNet *net.IPNet) error { + if len(userNet.IP) == 0 || len(userNet.Mask) == 0 { + return errors.Errorf("network %s's ip or mask cannot be empty", userNet.String()) + } + + ones, bit := userNet.Mask.Size() + if ones == 0 || bit == 0 { + return errors.Errorf("network %s's mask is invalid", userNet.String()) + } + networks, err := GetNetworksFromFilesystem(config) if err != nil { return err |