Skip to content

Commit fd87647

Browse files
committed
use "#nosec" instead of "nolint:gosec" to be more specific
The `#nosec` comment allows ignoring a specific rule; this prevents potentially other "gosec" linting failulres from being silently ignored. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 5da2ff5 commit fd87647

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

build/replicatedstream_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestSyncMultiReaderParallel(t *testing.T) {
4343
buf := make([]byte, bufferSize)
4444
for totalRead < len(data) {
4545
// Simulate random read sizes
46-
readSize := mathrand.Intn(bufferSize) //nolint:gosec
46+
readSize := mathrand.Intn(bufferSize) // #nosec G404 -- ignore "Use of weak random number generator (math/rand instead of crypto/rand)"
4747
n, err := reader.Read(buf[:readSize])
4848

4949
if n > 0 {
@@ -58,14 +58,15 @@ func TestSyncMultiReaderParallel(t *testing.T) {
5858

5959
assert.NoError(t, err, "Reader %d error", readerId)
6060

61-
if mathrand.Intn(1000) == 0 { //nolint:gosec
61+
// #nosec G404 -- ignore "Use of weak random number generator (math/rand instead of crypto/rand)"
62+
if mathrand.Intn(1000) == 0 {
6263
t.Logf("Reader %d closing", readerId)
6364
// Simulate random close
6465
return
6566
}
6667

6768
// Simulate random timing between reads
68-
time.Sleep(time.Millisecond * time.Duration(mathrand.Intn(5))) //nolint:gosec
69+
time.Sleep(time.Millisecond * time.Duration(mathrand.Intn(5))) // #nosec G404 -- ignore "Use of weak random number generator (math/rand instead of crypto/rand)"
6970
}
7071

7172
assert.Equal(t, len(data), totalRead, "Reader %d total read mismatch", readerId)

driver/kubernetes/podchooser/podchooser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (pc *RandomPodChooser) ChoosePod(ctx context.Context) (*corev1.Pod, error)
3737
if randSource == nil {
3838
randSource = rand.NewSource(time.Now().Unix())
3939
}
40-
rnd := rand.New(randSource) //nolint:gosec // no strong seeding required
40+
rnd := rand.New(randSource) // #nosec G404 -- no strong seeding required
4141
n := rnd.Int() % len(pods)
4242
logrus.Debugf("RandomPodChooser.ChoosePod(): len(pods)=%d, n=%d", len(pods), n)
4343
return pods[n], nil

0 commit comments

Comments
 (0)