Skip to content

Commit 27a5ffb

Browse files
authored
Quiet warnings about integer truncation (#586)
Both MinVersion and MaxVersion of crypto/tls.Config are uint16, so the int16 fields of rules.insecureConfigTLS are too small. GetInt() interprets integer literals as fitting within 64-bits, so simplify things by using int64.
1 parent bf2cd23 commit 27a5ffb

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

rules/tls.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ import (
2626

2727
type insecureConfigTLS struct {
2828
gosec.MetaData
29-
MinVersion int16
30-
MaxVersion int16
29+
MinVersion int64
30+
MaxVersion int64
3131
requiredType string
3232
goodCiphers []string
33-
actualMinVersion int16
34-
actualMaxVersion int16
33+
actualMinVersion int64
34+
actualMaxVersion int64
3535
}
3636

3737
func (t *insecureConfigTLS) ID() string {
@@ -86,7 +86,7 @@ func (t *insecureConfigTLS) processTLSConfVal(n *ast.KeyValueExpr, c *gosec.Cont
8686

8787
case "MinVersion":
8888
if ival, ierr := gosec.GetInt(n.Value); ierr == nil {
89-
t.actualMinVersion = (int16)(ival)
89+
t.actualMinVersion = ival
9090
} else {
9191
if se, ok := n.Value.(*ast.SelectorExpr); ok {
9292
if pkg, ok := se.X.(*ast.Ident); ok && pkg.Name == "tls" {
@@ -97,7 +97,7 @@ func (t *insecureConfigTLS) processTLSConfVal(n *ast.KeyValueExpr, c *gosec.Cont
9797

9898
case "MaxVersion":
9999
if ival, ierr := gosec.GetInt(n.Value); ierr == nil {
100-
t.actualMaxVersion = (int16)(ival)
100+
t.actualMaxVersion = ival
101101
} else {
102102
if se, ok := n.Value.(*ast.SelectorExpr); ok {
103103
if pkg, ok := se.X.(*ast.Ident); ok && pkg.Name == "tls" {
@@ -117,8 +117,8 @@ func (t *insecureConfigTLS) processTLSConfVal(n *ast.KeyValueExpr, c *gosec.Cont
117117
return nil
118118
}
119119

120-
func (t *insecureConfigTLS) mapVersion(version string) int16 {
121-
var v int16
120+
func (t *insecureConfigTLS) mapVersion(version string) int64 {
121+
var v int64
122122
switch version {
123123
case "VersionTLS13":
124124
v = tls.VersionTLS13

0 commit comments

Comments
 (0)