Skip to content

Commit

Permalink
Joinhostport added wherever required (#323)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nisarg1499 authored May 5, 2021
1 parent 4eb78b7 commit 17bd814
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/snapshot/client.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 17bd814

Please sign in to comment.