-
-
Notifications
You must be signed in to change notification settings - Fork 620
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check for usage of Rat.SetString in math/big with an overflow err…
…or (#819) * Add check for usage of Rat.SetString in math/big with an overflow error Rat.SetString in math/big in Go before 1.16.14 and 1.17.x before 1.17.7 has an overflow that can lead to Uncontrolled Memory Consumption. It is the CVE-2022-23772. * Use ContainsPkgCallExpr instead of manual parsing
- Loading branch information
1 parent
fb587c1
commit 9c19cb6
Showing
9 changed files
with
102 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package rules | ||
|
||
import ( | ||
"go/ast" | ||
|
||
"github.com/securego/gosec/v2" | ||
) | ||
|
||
type usingOldMathBig struct { | ||
gosec.MetaData | ||
calls gosec.CallList | ||
} | ||
|
||
func (r *usingOldMathBig) ID() string { | ||
return r.MetaData.ID | ||
} | ||
|
||
func (r *usingOldMathBig) Match(node ast.Node, ctx *gosec.Context) (gi *gosec.Issue, err error) { | ||
if callExpr := r.calls.ContainsPkgCallExpr(node, ctx, false); callExpr == nil { | ||
return nil, nil | ||
} | ||
|
||
confidence := gosec.Low | ||
major, minor, build := gosec.GoVersion() | ||
if major == 1 && (minor == 16 && build < 14 || minor == 17 && build < 7) { | ||
confidence = gosec.Medium | ||
} | ||
|
||
return gosec.NewIssue(ctx, node, r.ID(), r.What, r.Severity, confidence), nil | ||
} | ||
|
||
// NewUsingOldMathBig rule detects the use of Rat.SetString from math/big. | ||
func NewUsingOldMathBig(id string, _ gosec.Config) (gosec.Rule, []ast.Node) { | ||
calls := gosec.NewCallList() | ||
calls.Add("math/big.Rat", "SetString") | ||
return &usingOldMathBig{ | ||
calls: calls, | ||
MetaData: gosec.MetaData{ | ||
ID: id, | ||
What: "Potential uncontrolled memory consumption in Rat.SetString (CVE-2022-23772)", | ||
Severity: gosec.High, | ||
}, | ||
}, []ast.Node{(*ast.CallExpr)(nil)} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters