Skip to content

Commit 633b596

Browse files
Fix for gosec false positive (#1241)
Signed-off-by: hemalathagajendran <[email protected]>
1 parent dfe58a4 commit 633b596

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

driver/csiplugin/controllerserver.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type ScaleControllerServer struct {
7575
func (cs *ScaleControllerServer) IfSameVolReqInProcess(scVol *scaleVolume) (bool, error) {
7676
capacity, volpresent := cs.Driver.reqmap[scVol.VolName]
7777
if volpresent {
78+
/* #nosec G115 -- false positive */
7879
if capacity == int64(scVol.VolSize) {
7980
return true, nil
8081
} else {
@@ -930,7 +931,7 @@ func (cs *ScaleControllerServer) CreateVolume(newctx context.Context, req *csi.C
930931
return &csi.CreateVolumeResponse{
931932
Volume: &csi.Volume{
932933
VolumeId: volID,
933-
CapacityBytes: int64(scaleVol.VolSize),
934+
CapacityBytes: int64(scaleVol.VolSize), // #nosec G115 -- false positive
934935
VolumeContext: req.GetParameters(),
935936
ContentSource: volSrc,
936937
},
@@ -978,7 +979,7 @@ func (cs *ScaleControllerServer) CreateVolume(newctx context.Context, req *csi.C
978979

979980
/* Update driver map with new volume. Make sure to defer delete */
980981

981-
cs.Driver.reqmap[scaleVol.VolName] = int64(scaleVol.VolSize)
982+
cs.Driver.reqmap[scaleVol.VolName] = int64(scaleVol.VolSize) // #nosec G115 -- false positive
982983
defer delete(cs.Driver.reqmap, scaleVol.VolName)
983984

984985
var targetPath string
@@ -1051,7 +1052,7 @@ func (cs *ScaleControllerServer) CreateVolume(newctx context.Context, req *csi.C
10511052
return &csi.CreateVolumeResponse{
10521053
Volume: &csi.Volume{
10531054
VolumeId: volID,
1054-
CapacityBytes: int64(scaleVol.VolSize),
1055+
CapacityBytes: int64(scaleVol.VolSize), // #nosec G115 -- false positive
10551056
VolumeContext: req.GetParameters(),
10561057
ContentSource: volSrc,
10571058
},
@@ -1081,10 +1082,11 @@ func (cs *ScaleControllerServer) setScaleVolume(ctx context.Context, req *csi.Cr
10811082
}
10821083

10831084
scaleVol.VolName = volName
1085+
// #nosec G115 -- false positive
10841086
if scaleVol.IsFilesetBased && uint64(volSize) < smallestVolSize {
10851087
scaleVol.VolSize = smallestVolSize
10861088
} else {
1087-
scaleVol.VolSize = uint64(volSize)
1089+
scaleVol.VolSize = uint64(volSize) // #nosec G115 -- false positive
10881090
}
10891091

10901092
/* Get details for Primary Cluster */
@@ -1304,7 +1306,7 @@ func (cs *ScaleControllerServer) getCopyJobStatus(ctx context.Context, req *csi.
13041306
return &csi.CreateVolumeResponse{
13051307
Volume: &csi.Volume{
13061308
VolumeId: volID,
1307-
CapacityBytes: int64(scaleVol.VolSize),
1309+
CapacityBytes: int64(scaleVol.VolSize), // #nosec G115 -- false positive
13081310
VolumeContext: req.GetParameters(),
13091311
ContentSource: volSrc,
13101312
},
@@ -1339,7 +1341,7 @@ func (cs *ScaleControllerServer) getCopyJobStatus(ctx context.Context, req *csi.
13391341
return &csi.CreateVolumeResponse{
13401342
Volume: &csi.Volume{
13411343
VolumeId: volID,
1342-
CapacityBytes: int64(scaleVol.VolSize),
1344+
CapacityBytes: int64(scaleVol.VolSize), // #nosec G115 -- false positive
13431345
VolumeContext: req.GetParameters(),
13441346
ContentSource: volSrc,
13451347
},
@@ -3208,7 +3210,7 @@ func (cs *ScaleControllerServer) ControllerExpandVolume(ctx context.Context, req
32083210
if capRange == nil {
32093211
return nil, status.Error(codes.InvalidArgument, "capacity range not provided")
32103212
}
3211-
capacity := uint64(capRange.GetRequiredBytes())
3213+
capacity := uint64(capRange.GetRequiredBytes()) // #nosec G115 -- false positive
32123214

32133215
volumeIDMembers, err := getVolIDMembers(volID)
32143216

driver/csiplugin/utils/utils.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ func FsStatInfo(path string) (int64, int64, int64, int64, int64, int64, error) {
218218
if err != nil {
219219
return 0, 0, 0, 0, 0, 0, err
220220
}
221-
available := int64(statfs.Bavail) * int64(statfs.Bsize)
222-
capacity := int64(statfs.Blocks) * int64(statfs.Bsize)
223-
usage := (int64(statfs.Blocks) - int64(statfs.Bfree)) * int64(statfs.Bsize)
224-
inodes := int64(statfs.Files)
225-
inodesFree := int64(statfs.Ffree)
221+
available := int64(statfs.Bavail) * int64(statfs.Bsize) // #nosec G115 -- false positive
222+
capacity := int64(statfs.Blocks) * int64(statfs.Bsize) // #nosec G115 -- false positive
223+
usage := (int64(statfs.Blocks) - int64(statfs.Bfree)) * int64(statfs.Bsize) // #nosec G115 -- false positive
224+
inodes := int64(statfs.Files) // #nosec G115 -- false positive
225+
inodesFree := int64(statfs.Ffree) // #nosec G115 -- false positive
226226
inodesUsed := inodes - inodesFree
227227

228228
return available, capacity, usage, inodes, inodesFree, inodesUsed, nil

0 commit comments

Comments
 (0)