Skip to content

Commit 977ce8e

Browse files
henry118thaJeztah
authored andcommitted
Enable gosec linter for golangci-lint
`gosec` linter is able to identify issues described in #6584 e.g. $ git revert 54e95e6 [gosec dfc8ca1ec] Revert "fix Implicit memory aliasing in for loop" 2 files changed, 2 deletions(-) $ make check + proto-fmt + check GOGC=75 golangci-lint run containerstore.go:192:54: G601: Implicit memory aliasing in for loop. (gosec) containers = append(containers, containerFromProto(&container)) ^ image_store.go:132:42: G601: Implicit memory aliasing in for loop. (gosec) images = append(images, imageFromProto(&image)) ^ make: *** [check] Error 1 I also disabled following two settings which prevent the linter to show a complete list of issues. * max-issues-per-linter (default 50) * max-same-issues (default 3) Furthermore enabling gosec revealed many other issues. For now I blacklisted the ones except G601. Will create separate tasks to address them one by one moving next. Signed-off-by: Henry Wang <[email protected]> (cherry picked from commit b8bf504) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent c23945c commit 977ce8e

7 files changed

Lines changed: 22 additions & 0 deletions

File tree

.golangci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,28 @@ linters:
1111
- vet
1212
- unused
1313
- misspell
14+
- gosec
1415
disable:
1516
- errcheck
1617

1718
issues:
1819
include:
1920
- EXC0002
21+
max-issues-per-linter: 0
22+
max-same-issues: 0
23+
24+
linters-settings:
25+
gosec:
26+
# The following issues surfaced when `gosec` linter
27+
# was enabled. They are temporarily excluded to unblock
28+
# the existing workflow, but still to be addressed by
29+
# by future works.
30+
excludes:
31+
- G204
32+
- G305
33+
- G306
34+
- G402
35+
- G404
2036

2137
run:
2238
timeout: 8m

metadata/boltutil/helpers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func WriteExtensions(bkt *bolt.Bucket, extensions map[string]types.Any) error {
162162
}
163163

164164
for name, ext := range extensions {
165+
ext := ext
165166
p, err := proto.Marshal(&ext)
166167
if err != nil {
167168
return err

metadata/containers_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ func TestContainersList(t *testing.T) {
150150
}
151151

152152
for _, result := range results {
153+
result := result
153154
checkContainersEqual(t, &result, testset[result.ID], "list results did not match")
154155
}
155156
})

metadata/images_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ func TestImagesList(t *testing.T) {
129129
}
130130

131131
for _, result := range results {
132+
result := result
132133
checkImagesEqual(t, &result, testset[result.Name], "list results did not match")
133134
}
134135
})

oci/spec_opts_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ func TestDevShmSize(t *testing.T) {
593593

594594
expected := "1024k"
595595
for _, s := range ss {
596+
s := s
596597
if err := WithDevShmSize(1024)(nil, nil, nil, &s); err != nil {
597598
if err != ErrNoShmMount {
598599
t.Fatal(err)

services/containers/helpers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func containersToProto(containers []containers.Container) []api.Container {
2525
var containerspb []api.Container
2626

2727
for _, image := range containers {
28+
image := image
2829
containerspb = append(containerspb, containerToProto(&image))
2930
}
3031

services/images/helpers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func imagesToProto(images []images.Image) []imagesapi.Image {
2727
var imagespb []imagesapi.Image
2828

2929
for _, image := range images {
30+
image := image
3031
imagespb = append(imagespb, imageToProto(&image))
3132
}
3233

0 commit comments

Comments
 (0)