Skip to content

Commit 1d1afd0

Browse files
committed
Update golangci-lint to latest v1.62.2
Quite a lot of gosec ones about integers under/overflows - I tried to fix the ones that weren't problematic, but there were quite a lot.
1 parent c6fcb9c commit 1d1afd0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+112
-114
lines changed

Diff for: .golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# v1.60.1
1+
# v1.62.2
22
# Please don't remove the first line. It uses in CI to determine the golangci version
33
run:
44
timeout: 5m

Diff for: cloudapi/logs.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ func (sfn sleeperFunc) Sleep(d time.Duration) {
226226
// between the latest iteration and the next retry.
227227
// Interval is used as the base to compute an exponential backoff,
228228
// if the computed interval overtakes the max interval then max will be used.
229-
func retry(s sleeper, attempts uint, interval, maxDuration time.Duration, do func() error) (err error) {
229+
func retry(s sleeper, attempts int, interval, maxDuration time.Duration, do func() error) (err error) {
230230
baseInterval := math.Abs(interval.Truncate(time.Second).Seconds())
231231
r := rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec
232232

233-
for i := 0; i < int(attempts); i++ {
233+
for i := 0; i < attempts; i++ {
234234
if i > 0 {
235235
// wait = (interval ^ i) + random milliseconds
236236
wait := time.Duration(math.Pow(baseInterval, float64(i))) * time.Second

Diff for: cmd/report.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func createReport(u *usage.Usage, execScheduler *execution.Scheduler) map[string
2121
m["duration"] = execState.GetCurrentTestRunDuration().String()
2222
m["goos"] = runtime.GOOS
2323
m["goarch"] = runtime.GOARCH
24-
m["vus_max"] = uint64(execState.GetInitializedVUsCount())
24+
m["vus_max"] = uint64(execState.GetInitializedVUsCount()) //nolint:gosec
2525
m["iterations"] = execState.GetFullIterationCount()
2626
executors := make(map[string]int)
2727
for _, ec := range execScheduler.GetExecutorConfigs() {

Diff for: cmd/report_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestCreateReport(t *testing.T) {
4545
require.NoError(t, err)
4646

4747
s.GetState().ModInitializedVUsCount(6)
48-
s.GetState().AddFullIterations(uint64(opts.Iterations.Int64))
48+
s.GetState().AddFullIterations(uint64(opts.Iterations.Int64)) //nolint:gosec
4949
s.GetState().MarkStarted()
5050
time.Sleep(10 * time.Millisecond)
5151
s.GetState().MarkEnded()

Diff for: errext/abort_reason.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ func WithAbortReasonIfNone(err error, abortReason AbortReason) error {
3636
// The given error already has an abort reason, do nothing
3737
return err
3838
}
39-
return withAbortReason{err, abortReason}
39+
return withAbortReasonError{err, abortReason}
4040
}
4141

42-
type withAbortReason struct {
42+
type withAbortReasonError struct {
4343
error
4444
abortReason AbortReason
4545
}
4646

47-
func (ar withAbortReason) Unwrap() error {
47+
func (ar withAbortReasonError) Unwrap() error {
4848
return ar.error
4949
}
5050

51-
func (ar withAbortReason) AbortReason() AbortReason {
51+
func (ar withAbortReasonError) AbortReason() AbortReason {
5252
return ar.abortReason
5353
}
5454

55-
var _ HasAbortReason = withAbortReason{}
55+
var _ HasAbortReason = withAbortReasonError{}

Diff for: errext/exit_code.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ func WithExitCodeIfNone(err error, exitCode exitcodes.ExitCode) error {
3030
// The given error already has an exit code, do nothing
3131
return err
3232
}
33-
return withExitCode{err, exitCode}
33+
return withExitCodeError{err, exitCode}
3434
}
3535

36-
type withExitCode struct {
36+
type withExitCodeError struct {
3737
error
3838
exitCode exitcodes.ExitCode
3939
}
4040

41-
func (wh withExitCode) Unwrap() error {
41+
func (wh withExitCodeError) Unwrap() error {
4242
return wh.error
4343
}
4444

45-
func (wh withExitCode) ExitCode() exitcodes.ExitCode {
45+
func (wh withExitCodeError) ExitCode() exitcodes.ExitCode {
4646
return wh.exitCode
4747
}
4848

49-
var _ HasExitCode = withExitCode{}
49+
var _ HasExitCode = withExitCodeError{}

Diff for: errext/format_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestFormat(t *testing.T) {
2828

2929
t.Run("Exception", func(t *testing.T) {
3030
t.Parallel()
31-
err := fakeException{error: errors.New("simple error"), stack: "stack trace"}
31+
err := fakeExceptionError{error: errors.New("simple error"), stack: "stack trace"}
3232
errorText, fields := errext.Format(err)
3333
assert.Equal(t, "stack trace", errorText)
3434
assert.Empty(t, fields)
@@ -44,27 +44,27 @@ func TestFormat(t *testing.T) {
4444

4545
t.Run("ExceptionWithHint", func(t *testing.T) {
4646
t.Parallel()
47-
err := fakeException{error: errext.WithHint(errors.New("error with hint"), "hint message"), stack: "stack trace"}
47+
err := fakeExceptionError{error: errext.WithHint(errors.New("error with hint"), "hint message"), stack: "stack trace"}
4848
errorText, fields := errext.Format(err)
4949
assert.Equal(t, "stack trace", errorText)
5050
assert.Equal(t, map[string]interface{}{"hint": "hint message"}, fields)
5151
})
5252
}
5353

54-
type fakeException struct {
54+
type fakeExceptionError struct {
5555
error
5656
stack string
5757
abort errext.AbortReason
5858
}
5959

60-
func (e fakeException) StackTrace() string {
60+
func (e fakeExceptionError) StackTrace() string {
6161
return e.stack
6262
}
6363

64-
func (e fakeException) AbortReason() errext.AbortReason {
64+
func (e fakeExceptionError) AbortReason() errext.AbortReason {
6565
return e.abort
6666
}
6767

68-
func (e fakeException) Unwrap() error {
68+
func (e fakeExceptionError) Unwrap() error {
6969
return e.error
7070
}

Diff for: errext/hint.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ func WithHint(err error, hint string) error {
1818
if err == nil {
1919
return nil // No error, do nothing
2020
}
21-
return withHint{err, hint}
21+
return withHintError{err, hint}
2222
}
2323

24-
type withHint struct {
24+
type withHintError struct {
2525
error
2626
hint string
2727
}
2828

29-
func (wh withHint) Unwrap() error {
29+
func (wh withHintError) Unwrap() error {
3030
return wh.error
3131
}
3232

33-
func (wh withHint) Hint() string {
33+
func (wh withHintError) Hint() string {
3434
hint := wh.hint
3535
var oldhint HasHint
3636
if errors.As(wh.error, &oldhint) {
@@ -41,4 +41,4 @@ func (wh withHint) Hint() string {
4141
return hint
4242
}
4343

44-
var _ HasHint = withHint{}
44+
var _ HasHint = withHintError{}

Diff for: execution/scheduler.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (e *Scheduler) getRunStats() string {
151151
status = fmt.Sprintf("%s (%s)", status, pb.GetFixedLengthDuration(dur, e.maxDuration))
152152
}
153153

154-
vusFmt := pb.GetFixedLengthIntFormat(int64(e.maxPossibleVUs))
154+
vusFmt := pb.GetFixedLengthIntFormat(int64(e.maxPossibleVUs)) //nolint:gosec
155155
return fmt.Sprintf(
156156
"%s, "+vusFmt+"/"+vusFmt+" VUs, %d complete and %d interrupted iterations",
157157
status, e.state.GetCurrentlyActiveVUsCount(), e.state.GetInitializedVUsCount(),
@@ -268,7 +268,7 @@ func (e *Scheduler) initVUsAndExecutors(ctx context.Context, samplesOut chan<- m
268268
doneInits := e.initVUsConcurrently(subctx, samplesOut, vusToInitialize, runtime.GOMAXPROCS(0), logger)
269269

270270
initializedVUs := new(uint64)
271-
vusFmt := pb.GetFixedLengthIntFormat(int64(vusToInitialize))
271+
vusFmt := pb.GetFixedLengthIntFormat(int64(vusToInitialize)) //nolint:gosec
272272
e.initProgress.Modify(
273273
pb.WithProgress(func() (float64, []string) {
274274
doneVUs := atomic.LoadUint64(initializedVUs)

Diff for: js/bundle.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func (b *Bundle) newCompiler(logger logrus.FieldLogger) *compiler.Compiler {
296296

297297
func (b *Bundle) instantiate(vuImpl *moduleVUImpl, vuID uint64) (*BundleInstance, error) {
298298
rt := vuImpl.runtime
299-
err := b.setupJSRuntime(rt, int64(vuID), b.preInitState.Logger)
299+
err := b.setupJSRuntime(rt, vuID, b.preInitState.Logger)
300300
if err != nil {
301301
return nil, err
302302
}
@@ -375,7 +375,7 @@ func (b *Bundle) instantiate(vuImpl *moduleVUImpl, vuID uint64) (*BundleInstance
375375
return bi, nil
376376
}
377377

378-
func (b *Bundle) setupJSRuntime(rt *sobek.Runtime, vuID int64, logger logrus.FieldLogger) error {
378+
func (b *Bundle) setupJSRuntime(rt *sobek.Runtime, vuID uint64, logger logrus.FieldLogger) error {
379379
rt.SetFieldNameMapper(common.FieldNameMapper{})
380380
rt.SetRandSource(common.NewRandSource())
381381

Diff for: js/bundle_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -870,15 +870,15 @@ func TestBundleNotSharable(t *testing.T) {
870870
require.NoError(t, err)
871871

872872
bundles := map[string]*Bundle{"Source": b1, "Archive": b2}
873-
vus, iters := 10, 1000
873+
var vus, iters uint64 = 10, 1000
874874
for name, b := range bundles {
875875
b := b
876876
t.Run(name, func(t *testing.T) {
877877
t.Parallel()
878-
for i := 0; i < vus; i++ {
879-
bi, err := b.Instantiate(context.Background(), uint64(i))
878+
for i := uint64(0); i < vus; i++ {
879+
bi, err := b.Instantiate(context.Background(), i)
880880
require.NoError(t, err)
881-
for j := 0; j < iters; j++ {
881+
for j := uint64(0); j < iters; j++ {
882882
require.NoError(t, bi.Runtime.Set("__ITER", j))
883883
_, err := bi.getCallableExport(consts.DefaultFn)(sobek.Undefined())
884884
require.NoError(t, err)

Diff for: js/modules/k6/crypto/crypto.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
"fmt"
1515
"hash"
1616

17-
"golang.org/x/crypto/md4" //nolint:staticcheck // #nosec G501 // MD4 is weak, but we need it for compatibility
18-
"golang.org/x/crypto/ripemd160" // no lint:staticcheck // #nosec G501 // RIPEMD160 is weak, but we need it for compatibility
17+
"golang.org/x/crypto/md4" //nolint:staticcheck,gosec // MD4 is weak, but we need it for compatibility
18+
"golang.org/x/crypto/ripemd160" //nolint:staticcheck,gosec // RIPEMD160 is weak, but we need it for compatibility
1919

2020
"github.com/grafana/sobek"
2121

Diff for: js/modules/k6/crypto/x509/x509.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
package x509
33

44
import (
5-
"crypto/dsa" // #nosec G505 // DSA is weak, but we need it for compatibility
5+
"crypto/dsa" //nolint:staticcheck // DSA is weak, but we need it for compatibility
66
"crypto/ecdsa"
77
"crypto/rsa"
88
"crypto/sha1" // #nosec G505

Diff for: js/modules/k6/execution/execution.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ func (mi *ModuleInstance) newScenarioInfo() (*sobek.Object, error) {
127127
return newInfoObj(rt, si)
128128
}
129129

130-
//nolint:lll,gochecknoglobals
131-
var instanceInfoInitContextErr = common.NewInitContextError("getting instance information in the init context is not supported")
130+
//nolint:lll
131+
var errInstanceInfoInitContext = common.NewInitContextError("getting instance information in the init context is not supported")
132132

133133
// newInstanceInfo returns a sobek.Object with property accessors to retrieve
134134
// information about the local instance stats.
135135
func (mi *ModuleInstance) newInstanceInfo() (*sobek.Object, error) {
136136
es := lib.GetExecutionState(mi.vu.Context())
137137
if es == nil {
138-
return nil, instanceInfoInitContextErr
138+
return nil, errInstanceInfoInitContext
139139
}
140140
rt := mi.vu.Runtime()
141141

@@ -160,8 +160,7 @@ func (mi *ModuleInstance) newInstanceInfo() (*sobek.Object, error) {
160160
return newInfoObj(rt, ti)
161161
}
162162

163-
//nolint:gochecknoglobals
164-
var testInfoInitContextErr = common.NewInitContextError("getting test options in the init context is not supported")
163+
var errTestInfoInitContext = common.NewInitContextError("getting test options in the init context is not supported")
165164

166165
// newTestInfo returns a sobek.Object with property accessors to retrieve
167166
// information and control execution of the overall test run.
@@ -184,7 +183,7 @@ func (mi *ModuleInstance) newTestInfo() (*sobek.Object, error) {
184183
"options": func() interface{} {
185184
vuState := mi.vu.State()
186185
if vuState == nil {
187-
common.Throw(rt, testInfoInitContextErr)
186+
common.Throw(rt, errTestInfoInitContext)
188187
}
189188
if optionsObject == nil {
190189
opts, err := optionsAsObject(rt, vuState.Options)
@@ -200,15 +199,14 @@ func (mi *ModuleInstance) newTestInfo() (*sobek.Object, error) {
200199
return newInfoObj(rt, ti)
201200
}
202201

203-
//nolint:gochecknoglobals
204-
var vuInfoInitContextErr = common.NewInitContextError("getting VU information in the init context is not supported")
202+
var errVUInfoInitContex = common.NewInitContextError("getting VU information in the init context is not supported")
205203

206204
// newVUInfo returns a sobek.Object with property accessors to retrieve
207205
// information about the currently executing VU.
208206
func (mi *ModuleInstance) newVUInfo() (*sobek.Object, error) {
209207
vuState := mi.vu.State()
210208
if vuState == nil {
211-
return nil, vuInfoInitContextErr
209+
return nil, errVUInfoInitContex
212210
}
213211
rt := mi.vu.Runtime()
214212

Diff for: js/modules/k6/grpc/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func decryptPrivateKey(key, password []byte) ([]byte, error) {
125125
being used here because it is deprecated due to it not supporting *good* cryptography
126126
ultimately though we want to support something so we will be using it for now.
127127
*/
128-
decryptedKey, err := x509.DecryptPEMBlock(block, password)
128+
decryptedKey, err := x509.DecryptPEMBlock(block, password) //nolint:staticcheck
129129
if err != nil {
130130
return nil, err
131131
}

Diff for: js/modules/k6/timers/timers_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func TestSetTimeoutContextCancel(t *testing.T) {
173173
for i := 0; i < 2000; i++ {
174174
ctx, cancel := context.WithCancel(context.Background())
175175
runtime.CancelContext = cancel
176-
runtime.VU.CtxField = ctx
176+
runtime.VU.CtxField = ctx //nolint:fatcontext
177177
runtime.VU.RuntimeField.ClearInterrupt()
178178
const interruptMsg = "definitely an interrupt"
179179
go func() {

Diff for: js/runner.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ func (r *Runner) newVU(
172172
tlsConfig := &tls.Config{
173173
InsecureSkipVerify: r.Bundle.Options.InsecureSkipTLSVerify.Bool, //nolint:gosec
174174
CipherSuites: cipherSuites,
175-
MinVersion: uint16(tlsVersions.Min),
176-
MaxVersion: uint16(tlsVersions.Max),
175+
MinVersion: uint16(tlsVersions.Min), //nolint:gosec
176+
MaxVersion: uint16(tlsVersions.Max), //nolint:gosec
177177
Certificates: certs,
178178
Renegotiation: tls.RenegotiateFreelyAsClient,
179179
KeyLogWriter: r.preInitState.KeyLogger,
@@ -188,7 +188,7 @@ func (r *Runner) newVU(
188188
"deprecation - https://pkg.go.dev/crypto/[email protected]#Config.",
189189
)
190190
})
191-
tlsConfig.NameToCertificate = nameToCert
191+
tlsConfig.NameToCertificate = nameToCert //nolint:staticcheck
192192
}
193193
transport := &http.Transport{
194194
Proxy: http.ProxyFromEnvironment,

Diff for: js/runner_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ func TestVUIntegrationTLSConfig(t *testing.T) {
12041204
"",
12051205
},
12061206
"UnsupportedVersion": {
1207-
lib.Options{TLSVersion: &lib.TLSVersions{Min: tls.VersionSSL30, Max: tls.VersionSSL30}},
1207+
lib.Options{TLSVersion: &lib.TLSVersions{Min: tls.VersionSSL30, Max: tls.VersionSSL30}}, //nolint:staticcheck
12081208
unsupportedVersionErrorMsg,
12091209
},
12101210
}
@@ -2070,7 +2070,7 @@ func TestSystemTags(t *testing.T) {
20702070
ctx, cancel := context.WithCancel(context.Background())
20712071
defer cancel()
20722072

2073-
vu, err := r.NewVU(ctx, uint64(num), 0, samples)
2073+
vu, err := r.NewVU(ctx, uint64(num), 0, samples) //nolint:gosec
20742074
require.NoError(t, err)
20752075
activeVU := vu.Activate(&lib.VUActivationParams{
20762076
RunContext: ctx,

Diff for: lib/archive.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func ReadArchive(in io.Reader) (*Archive, error) {
125125
}
126126
return nil, err
127127
}
128-
if hdr.Typeflag != tar.TypeReg && hdr.Typeflag != tar.TypeRegA {
128+
if hdr.Typeflag != tar.TypeReg && hdr.Typeflag != tar.TypeRegA { //nolint:staticcheck
129129
continue
130130
}
131131

@@ -166,7 +166,7 @@ func ReadArchive(in io.Reader) (*Archive, error) {
166166
case "https", "file":
167167
fileSystem := arc.getFs(pfx)
168168
name = filepath.FromSlash(name)
169-
if err = fsext.WriteFile(fileSystem, name, data, fs.FileMode(hdr.Mode)); err != nil {
169+
if err = fsext.WriteFile(fileSystem, name, data, fs.FileMode(hdr.Mode)); err != nil { //nolint:gosec
170170
return nil, err
171171
}
172172
if err = fileSystem.Chtimes(name, hdr.AccessTime, hdr.ModTime); err != nil {

Diff for: lib/execution.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func NewExecutionState(
207207
resumeNotify := make(chan struct{})
208208
close(resumeNotify) // By default the ExecutionState starts unpaused
209209

210-
maxUnplannedUninitializedVUs := int64(maxPossibleVUs - maxPlannedVUs)
210+
maxUnplannedUninitializedVUs := int64(maxPossibleVUs - maxPlannedVUs) //nolint:gosec
211211

212212
segIdx := NewSegmentedIndex(et)
213213
return &ExecutionState{
@@ -240,7 +240,7 @@ func (es *ExecutionState) GetUniqueVUIdentifiers() (uint64, uint64) {
240240
es.vuIDSegIndexMx.Lock()
241241
defer es.vuIDSegIndexMx.Unlock()
242242
scaled, unscaled := es.vuIDSegIndex.Next()
243-
return uint64(scaled), uint64(unscaled)
243+
return uint64(scaled), uint64(unscaled) //nolint:gosec
244244
}
245245

246246
// GetInitializedVUsCount returns the total number of currently initialized VUs.

Diff for: lib/executor/base_executor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (bs *BaseExecutor) nextIterationCounters() (uint64, uint64) {
4747
bs.iterSegIndexMx.Lock()
4848
defer bs.iterSegIndexMx.Unlock()
4949
scaled, unscaled := bs.iterSegIndex.Next()
50-
return uint64(scaled - 1), uint64(unscaled - 1)
50+
return uint64(scaled - 1), uint64(unscaled - 1) //nolint:gosec
5151
}
5252

5353
// Init doesn't do anything for most executors, since initialization of all

0 commit comments

Comments
 (0)