From 599fa5583eddad2176cb6075b53b4c9a0a6a7694 Mon Sep 17 00:00:00 2001 From: zouyee Date: Wed, 2 Oct 2019 08:55:08 +0800 Subject: [PATCH] IP validates if a string is a valid IP address Signed-off-by: Zou Nengren --- pkg/volume/glusterfs/glusterfs.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/volume/glusterfs/glusterfs.go b/pkg/volume/glusterfs/glusterfs.go index 1bf0402fff4..a3b4866a292 100644 --- a/pkg/volume/glusterfs/glusterfs.go +++ b/pkg/volume/glusterfs/glusterfs.go @@ -20,6 +20,7 @@ import ( "fmt" "math" "math/rand" + "net" "os" "path/filepath" "runtime" @@ -29,7 +30,7 @@ import ( gcli "github.com/heketi/heketi/client/api/go-client" gapi "github.com/heketi/heketi/pkg/glusterfs/api" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -968,6 +969,11 @@ func getClusterNodes(cli *gcli.Client, cluster string) (dynamicHostIps []string, return nil, fmt.Errorf("failed to get host ipaddress: %v", err) } ipaddr := dstrings.Join(nodeInfo.NodeAddRequest.Hostnames.Storage, "") + // IP validates if a string is a valid IP address. + ip := net.ParseIP(ipaddr) + if ip == nil { + return nil, fmt.Errorf("glusterfs server node ip address %s must be a valid IP address, (e.g. 10.9.8.7)", ipaddr) + } dynamicHostIps = append(dynamicHostIps, ipaddr) } klog.V(3).Infof("host list :%v", dynamicHostIps)