aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/securego
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2024-11-11 11:41:38 +0100
committerTaras Madan <tarasmadan@google.com>2024-11-11 11:10:48 +0000
commit27e76fae2ee2d84dc7db63af1d9ed7358ba35b7a (patch)
treeed19c0e35e272b3c4cc5a2f2c595e035b2428337 /vendor/github.com/securego
parent621e84e063b0e15b23e17780338627c509e1b9e8 (diff)
vendor: update
Diffstat (limited to 'vendor/github.com/securego')
-rw-r--r--vendor/github.com/securego/gosec/v2/action.yml2
-rw-r--r--vendor/github.com/securego/gosec/v2/analyzers/analyzerslist.go2
-rw-r--r--vendor/github.com/securego/gosec/v2/analyzers/conversion_overflow.go92
3 files changed, 65 insertions, 31 deletions
diff --git a/vendor/github.com/securego/gosec/v2/action.yml b/vendor/github.com/securego/gosec/v2/action.yml
index d4bc351c8..2b2deaab7 100644
--- a/vendor/github.com/securego/gosec/v2/action.yml
+++ b/vendor/github.com/securego/gosec/v2/action.yml
@@ -10,7 +10,7 @@ inputs:
runs:
using: 'docker'
- image: 'docker://securego/gosec:2.21.1'
+ image: 'docker://securego/gosec:2.21.3'
args:
- ${{ inputs.args }}
diff --git a/vendor/github.com/securego/gosec/v2/analyzers/analyzerslist.go b/vendor/github.com/securego/gosec/v2/analyzers/analyzerslist.go
index f2157442f..8d222384a 100644
--- a/vendor/github.com/securego/gosec/v2/analyzers/analyzerslist.go
+++ b/vendor/github.com/securego/gosec/v2/analyzers/analyzerslist.go
@@ -51,7 +51,7 @@ func (al *AnalyzerList) AnalyzersInfo() (map[string]AnalyzerDefinition, map[stri
type AnalyzerFilter func(string) bool
// NewAnalyzerFilter is a closure that will include/exclude the analyzer ID's based on
-// the supplied boolean value.
+// the supplied boolean value (false means don't remove, true means exclude).
func NewAnalyzerFilter(action bool, analyzerIDs ...string) AnalyzerFilter {
analyzerlist := make(map[string]bool)
for _, analyzer := range analyzerIDs {
diff --git a/vendor/github.com/securego/gosec/v2/analyzers/conversion_overflow.go b/vendor/github.com/securego/gosec/v2/analyzers/conversion_overflow.go
index 3ef4825af..bebe9b834 100644
--- a/vendor/github.com/securego/gosec/v2/analyzers/conversion_overflow.go
+++ b/vendor/github.com/securego/gosec/v2/analyzers/conversion_overflow.go
@@ -40,7 +40,7 @@ type integer struct {
type rangeResult struct {
minValue int
maxValue uint
- explixitPositiveVals []uint
+ explicitPositiveVals []uint
explicitNegativeVals []int
isRangeCheck bool
convertFound bool
@@ -271,7 +271,7 @@ func hasExplicitRangeCheck(instr *ssa.Convert, dstType string) bool {
if result.isRangeCheck {
minValue = max(minValue, &result.minValue)
maxValue = min(maxValue, &result.maxValue)
- explicitPositiveVals = append(explicitPositiveVals, result.explixitPositiveVals...)
+ explicitPositiveVals = append(explicitPositiveVals, result.explicitPositiveVals...)
explicitNegativeVals = append(explicitNegativeVals, result.explicitNegativeVals...)
}
case *ssa.Call:
@@ -325,16 +325,17 @@ func getResultRange(ifInstr *ssa.If, instr *ssa.Convert, visitedIfs map[*ssa.If]
result.convertFound = true
result.minValue = max(result.minValue, thenBounds.minValue)
result.maxValue = min(result.maxValue, thenBounds.maxValue)
- result.explixitPositiveVals = append(result.explixitPositiveVals, thenBounds.explixitPositiveVals...)
- result.explicitNegativeVals = append(result.explicitNegativeVals, thenBounds.explicitNegativeVals...)
} else if elseBounds.convertFound {
result.convertFound = true
result.minValue = max(result.minValue, elseBounds.minValue)
result.maxValue = min(result.maxValue, elseBounds.maxValue)
- result.explixitPositiveVals = append(result.explixitPositiveVals, elseBounds.explixitPositiveVals...)
- result.explicitNegativeVals = append(result.explicitNegativeVals, elseBounds.explicitNegativeVals...)
}
+ result.explicitPositiveVals = append(result.explicitPositiveVals, thenBounds.explixitPositiveVals...)
+ result.explicitNegativeVals = append(result.explicitNegativeVals, thenBounds.explicitNegativeVals...)
+ result.explicitPositiveVals = append(result.explicitPositiveVals, elseBounds.explixitPositiveVals...)
+ result.explicitNegativeVals = append(result.explicitNegativeVals, elseBounds.explicitNegativeVals...)
+
return result
}
@@ -344,15 +345,26 @@ func updateResultFromBinOp(result *rangeResult, binOp *ssa.BinOp, instr *ssa.Con
operandsFlipped := false
compareVal, op := getRealValueFromOperation(instr.X)
- if x != compareVal {
- y, operandsFlipped = x, true
+
+ // Handle FieldAddr
+ if fieldAddr, ok := compareVal.(*ssa.FieldAddr); ok {
+ compareVal = fieldAddr
+ }
+
+ if !isSameOrRelated(x, compareVal) {
+ y = x
+ operandsFlipped = true
}
constVal, ok := y.(*ssa.Const)
if !ok {
return
}
-
+ // TODO: constVal.Value nil check avoids #1229 panic but seems to be hiding a bug in the code above or in x/tools/go/ssa.
+ if constVal.Value == nil {
+ // log.Fatalf("[gosec] constVal.Value is nil flipped=%t, constVal=%#v, binOp=%#v", operandsFlipped, constVal, binOp)
+ return
+ }
switch binOp.Op {
case token.LEQ, token.LSS:
updateMinMaxForLessOrEqual(result, constVal, binOp.Op, operandsFlipped, successPathConvert)
@@ -362,25 +374,12 @@ func updateResultFromBinOp(result *rangeResult, binOp *ssa.BinOp, instr *ssa.Con
if !successPathConvert {
break
}
-
- // Determine if the constant value is positive or negative.
- if strings.Contains(constVal.String(), "-") {
- result.explicitNegativeVals = append(result.explicitNegativeVals, int(constVal.Int64()))
- } else {
- result.explixitPositiveVals = append(result.explixitPositiveVals, uint(constVal.Uint64()))
- }
-
+ updateExplicitValues(result, constVal)
case token.NEQ:
if successPathConvert {
break
}
-
- // Determine if the constant value is positive or negative.
- if strings.Contains(constVal.String(), "-") {
- result.explicitNegativeVals = append(result.explicitNegativeVals, int(constVal.Int64()))
- } else {
- result.explixitPositiveVals = append(result.explixitPositiveVals, uint(constVal.Uint64()))
- }
+ updateExplicitValues(result, constVal)
}
if op == "neg" {
@@ -391,11 +390,19 @@ func updateResultFromBinOp(result *rangeResult, binOp *ssa.BinOp, instr *ssa.Con
result.maxValue = uint(min)
}
if max <= math.MaxInt {
- result.minValue = int(max) //nolint:gosec
+ result.minValue = int(max)
}
}
}
+func updateExplicitValues(result *rangeResult, constVal *ssa.Const) {
+ if strings.Contains(constVal.String(), "-") {
+ result.explicitNegativeVals = append(result.explicitNegativeVals, int(constVal.Int64()))
+ } else {
+ result.explicitPositiveVals = append(result.explicitPositiveVals, uint(constVal.Uint64()))
+ }
+}
+
func updateMinMaxForLessOrEqual(result *rangeResult, constVal *ssa.Const, op token.Token, operandsFlipped bool, successPathConvert bool) {
// If the success path has a conversion and the operands are not flipped, then the constant value is the maximum value.
if successPathConvert && !operandsFlipped {
@@ -439,6 +446,8 @@ func walkBranchForConvert(block *ssa.BasicBlock, instr *ssa.Convert, visitedIfs
if result.isRangeCheck {
bounds.minValue = toPtr(max(result.minValue, bounds.minValue))
bounds.maxValue = toPtr(min(result.maxValue, bounds.maxValue))
+ bounds.explixitPositiveVals = append(bounds.explixitPositiveVals, result.explicitPositiveVals...)
+ bounds.explicitNegativeVals = append(bounds.explicitNegativeVals, result.explicitNegativeVals...)
}
case *ssa.Call:
if v == instr.X {
@@ -463,9 +472,10 @@ func isRangeCheck(v ssa.Value, x ssa.Value) bool {
switch op := v.(type) {
case *ssa.BinOp:
switch op.Op {
- case token.LSS, token.LEQ, token.GTR, token.GEQ,
- token.EQL, token.NEQ:
- return op.X == compareVal || op.Y == compareVal
+ case token.LSS, token.LEQ, token.GTR, token.GEQ, token.EQL, token.NEQ:
+ leftMatch := isSameOrRelated(op.X, compareVal)
+ rightMatch := isSameOrRelated(op.Y, compareVal)
+ return leftMatch || rightMatch
}
}
return false
@@ -475,12 +485,36 @@ func getRealValueFromOperation(v ssa.Value) (ssa.Value, string) {
switch v := v.(type) {
case *ssa.UnOp:
if v.Op == token.SUB {
- return v.X, "neg"
+ val, _ := getRealValueFromOperation(v.X)
+ return val, "neg"
}
+ return getRealValueFromOperation(v.X)
+ case *ssa.FieldAddr:
+ return v, "field"
+ case *ssa.Alloc:
+ return v, "alloc"
}
return v, ""
}
+func isSameOrRelated(a, b ssa.Value) bool {
+ aVal, _ := getRealValueFromOperation(a)
+ bVal, _ := getRealValueFromOperation(b)
+
+ if aVal == bVal {
+ return true
+ }
+
+ // Check if both are FieldAddr operations referring to the same field of the same struct
+ if aField, aOk := aVal.(*ssa.FieldAddr); aOk {
+ if bField, bOk := bVal.(*ssa.FieldAddr); bOk {
+ return aField.X == bField.X && aField.Field == bField.Field
+ }
+ }
+
+ return false
+}
+
func explicitValsInRange(explicitPosVals []uint, explicitNegVals []int, dstInt integer) bool {
if len(explicitPosVals) == 0 && len(explicitNegVals) == 0 {
return false