Skip to content

Commit d442c8d

Browse files
authored
enable gosec linter and fix the errors it reports. (#390)
1 parent e03230a commit d442c8d

File tree

51 files changed

+117
-75
lines changed

Some content is hidden

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

51 files changed

+117
-75
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ linters-settings:
1616
linters:
1717
enable:
1818
- bodyclose
19+
- gosec
1920
- gocritic
2021
- gocyclo
2122
- gofmt

v23/flow/message/internal_message_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ import (
2121
func randomTestCases() []uint64 {
2222
c := make([]uint64, 4096)
2323
for i := range c {
24-
c[i] = rand.Uint64()
24+
c[i] = rand.Uint64() //nolint:gosec
2525
}
2626
return c
2727
}
2828

2929
func randomMaxTestCases(limit int64) []uint64 {
3030
c := make([]uint64, 4096)
3131
for i := range c {
32-
c[i] = uint64(rand.Int63n(limit))
32+
c[i] = uint64(rand.Int63n(limit)) //nolint:gosec
3333
}
3434
return c
3535
}
@@ -38,7 +38,7 @@ func randomLargeTestCases() []uint64 {
3838
c := make([]uint64, 4096)
3939
for i := range c {
4040
for c[i] < math.MaxUint32 {
41-
c[i] = rand.Uint64()
41+
c[i] = rand.Uint64() //nolint:gosec
4242
}
4343
}
4444
return c

v23/security/algo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
func TestRSAPanic(t *testing.T) {
1818
// Make sure that using a key with < 2048 bits causes a panic.
19-
key, err := rsa.GenerateKey(rand.Reader, 1024)
19+
key, err := rsa.GenerateKey(rand.Reader, 1024) //nolint:gosec
2020
if err != nil {
2121
t.Fatal(err)
2222
}

v23/security/blessings_test.go

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

6161
func verifyBlessingSignatures(t *testing.T, blessings ...security.Blessings) {
6262
for _, b := range blessings {
63+
b := b
6364
if err := security.ExposeVerifySignature(&b); err != nil {
6465
_, _, line, _ := runtime.Caller(1)
6566
t.Fatalf("line %v: invalid signature for blessing %v: %v", line, b.String(), err)

v23/security/publickey.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"crypto"
99
"crypto/ecdsa"
1010
"crypto/ed25519"
11-
"crypto/md5"
11+
"crypto/md5" //nolint:gosec
1212
"crypto/rsa"
1313
"crypto/x509"
1414
"encoding"
@@ -108,7 +108,7 @@ func (pk publicKeyCommon) MarshalBinary() ([]byte, error) {
108108

109109
func (pk publicKeyCommon) String() string {
110110
const hextable = "0123456789abcdef"
111-
hash := md5.Sum(pk.keyBytes)
111+
hash := md5.Sum(pk.keyBytes) //nolint:gosec
112112
var repr [md5.Size * 3]byte
113113
for i, v := range hash {
114114
repr[i*3] = hextable[v>>4]

v23/security/signature.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package security
66

77
import (
88
"crypto"
9-
"crypto/sha1"
109
"crypto/sha256"
1110
"crypto/sha512"
1211
)
@@ -84,9 +83,9 @@ func messageDigest(hash crypto.Hash, purpose, message []byte, key PublicKey) []b
8483

8584
func cryptoSum(hash crypto.Hash, data []byte) []byte {
8685
switch hash {
87-
case crypto.SHA1:
88-
h := sha1.Sum(data)
89-
return h[:]
86+
// case crypto.SHA1:
87+
// h := sha1.Sum(data)
88+
// return h[:]
9089
case crypto.SHA256:
9190
h := sha256.Sum256(data)
9291
return h[:]
@@ -102,8 +101,8 @@ func cryptoSum(hash crypto.Hash, data []byte) []byte {
102101

103102
func cryptoHash(h Hash) crypto.Hash {
104103
switch h {
105-
case SHA1Hash:
106-
return crypto.SHA1
104+
// case SHA1Hash:
105+
// return crypto.SHA1
107106
case SHA256Hash:
108107
return crypto.SHA256
109108
case SHA384Hash:

v23/vdl/vdltest/entry_generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func NewEntryGenerator(sourceTypes []*vdl.Type) *EntryGenerator {
5656
valueGen: NewValueGenerator(sourceTypes),
5757
hasher: fnv.New64a(),
5858
randSeed: now,
59-
rng: rand.New(rand.NewSource(now)),
59+
rng: rand.New(rand.NewSource(now)), //nolint:gosec
6060
}
6161
for _, tt := range sourceTypes {
6262
kind := tt.NonOptional().Kind()

v23/vdl/vdltest/internal/vdltestgen/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const (
5151
vdltestPkgName = "v.io/v23/vdl/vdltest"
5252
typeGenFileName = "type_gen.vdl"
5353
typeManualFileName = "type_manual.vdl"
54-
passGenFileName = "entry_pass_gen.vdl"
54+
passGenFileName = "entry_pass_gen.vdl" //nolint:gosec
5555
failGenFileName = "entry_fail_gen.vdl"
5656
)
5757

v23/vdl/vdltest/type_generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func NewTypeGenerator() *TypeGenerator {
4646
BaseTypesPerKind: []int{3, 1},
4747
FieldsPerKind: []int{-1, 2, 1},
4848
MaxArrayLen: 3,
49-
rng: rand.New(rand.NewSource(time.Now().Unix())),
49+
rng: rand.New(rand.NewSource(time.Now().Unix())), //nolint:gosec
5050
}
5151
}
5252

v23/vdl/vdltest/value_generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func NewValueGenerator(types []*vdl.Type) *ValueGenerator {
3939
RandomZeroPercentage: 20,
4040
MaxLen: 3,
4141
MaxCycleDepth: 3,
42-
rng: rand.New(rand.NewSource(time.Now().Unix())),
42+
rng: rand.New(rand.NewSource(time.Now().Unix())), //nolint:gosec
4343
}
4444
}
4545

0 commit comments

Comments
 (0)