mirror of
https://github.com/securego/gosec.git
synced 2025-11-29 22:37:59 +02:00
Do not flag the unhandled errors which are explicitly ignored
fixes #270
This commit is contained in:
committed by
Cosmin Cojocar
parent
12400f9a1c
commit
14ed63d558
@@ -51,18 +51,6 @@ func returnsError(callExpr *ast.CallExpr, ctx *gosec.Context) int {
|
||||
|
||||
func (r *noErrorCheck) Match(n ast.Node, ctx *gosec.Context) (*gosec.Issue, error) {
|
||||
switch stmt := n.(type) {
|
||||
case *ast.AssignStmt:
|
||||
for _, expr := range stmt.Rhs {
|
||||
if callExpr, ok := expr.(*ast.CallExpr); ok && r.whitelist.ContainsCallExpr(expr, ctx, false) == nil {
|
||||
pos := returnsError(callExpr, ctx)
|
||||
if pos < 0 || pos >= len(stmt.Lhs) {
|
||||
return nil, nil
|
||||
}
|
||||
if id, ok := stmt.Lhs[pos].(*ast.Ident); ok && id.Name == "_" {
|
||||
return gosec.NewIssue(ctx, n, r.ID(), r.What, r.Severity, r.Confidence), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
case *ast.ExprStmt:
|
||||
if callExpr, ok := stmt.X.(*ast.CallExpr); ok && r.whitelist.ContainsCallExpr(stmt.X, ctx, false) == nil {
|
||||
pos := returnsError(callExpr, ctx)
|
||||
|
||||
Reference in New Issue
Block a user