From 17bd814298d558e169fd49ea4cc4370ff7118ee7 Mon Sep 17 00:00:00 2001 From: Nisarg Shah Date: Wed, 5 May 2021 20:01:40 +0530 Subject: [PATCH] Joinhostport added wherever required (#323) Replaced `fmt.Sprintf` with `net.JoinHostPort`, because `fmt.Sprintf` will cause issues in IPv6. The best practice is to use net.JoinHostPort Results: Fixed SemGrep complaint to use JoinHostPort instead of Sprintf for network address construction. Signed-off-by: nisarg1499 --- pkg/snapshot/client.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/snapshot/client.go b/pkg/snapshot/client.go index ec96efd3..7a875f22 100644 --- a/pkg/snapshot/client.go +++ b/pkg/snapshot/client.go @@ -18,6 +18,7 @@ import ( "context" "encoding/json" "fmt" + "net" "strings" v1proto "github.com/openebs/api/v2/pkg/proto" @@ -48,7 +49,7 @@ type SnapClient struct{} //CreateSnapshot creates snapshot by executing gRPC call func (s *SnapClient) CreateSnapshot(ip, volName, snapName string) (*v1proto.VolumeSnapCreateResponse, error) { var conn *grpc.ClientConn - conn, err := grpc.Dial(fmt.Sprintf("%s:%d", ip, VolumeGrpcListenPort), grpc.WithInsecure()) + conn, err := grpc.Dial(net.JoinHostPort(ip, fmt.Sprintf("%d", VolumeGrpcListenPort)), grpc.WithInsecure()) if err != nil { return nil, errors.Errorf("Unable to dial gRPC server on port %d error : %s", VolumeGrpcListenPort, err) } @@ -80,7 +81,7 @@ func (s *SnapClient) CreateSnapshot(ip, volName, snapName string) (*v1proto.Volu //DestroySnapshot destroys snapshots by executing gRPC calls func (s *SnapClient) DestroySnapshot(ip, volName, snapName string) (*v1proto.VolumeSnapDeleteResponse, error) { var conn *grpc.ClientConn - conn, err := grpc.Dial(fmt.Sprintf("%s:%d", ip, VolumeGrpcListenPort), grpc.WithInsecure()) + conn, err := grpc.Dial(net.JoinHostPort(ip, fmt.Sprintf("%d", VolumeGrpcListenPort)), grpc.WithInsecure()) if err != nil { return nil, errors.Errorf("Unable to dial gRPC server on port error : %s", err) }