-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental semgrep rule 'if-incorrect-nil-err-return'
Put in experimental directory because of huge count of false positives.
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
rules: | ||
- id: if-incorrect-nil-err-return | ||
languages: [go] | ||
severity: WARNING | ||
message: | | ||
WARNING: A local variable '$ERR' is checked for nil, but a different variable is returned. | ||
Ensure that the returned variable is the one that was checked or properly wrapped! | ||
patterns: | ||
- metavariable-regex: | ||
metavariable: $ERR | ||
regex: .*(?i)err # using .* to allow prefixes, because regex matching is left anchored. | ||
|
||
- pattern: | | ||
if $ERR != nil { | ||
... | ||
return ..., $OTHERERR | ||
} | ||
- pattern-not: | | ||
if $ERR != nil { | ||
... | ||
return ..., $ERR | ||
} | ||
- pattern-not: | | ||
if $ERR != nil { | ||
... | ||
return ..., $ANYFUNC(..., $ERR, ...) | ||
} | ||
- pattern-not: | | ||
if $ERR != nil { | ||
... | ||
return ..., $ANYFUNC(..., $ANYFUNC1(..., $ERR, ...), ...) | ||
} | ||
- pattern-not: | | ||
if $ERR != nil { | ||
... | ||
$NEWERR := $ANYFUNC(..., $ERR, ...) | ||
... | ||
return nil, $NEWERR | ||
} | ||
- pattern-not: | | ||
if $ERR != nil { | ||
... | ||
$NEWERR := $ANYFUNC(..., $ERR, ...) | ||
... | ||
return ..., $ANYFUNC1(..., $NEWERR, ...) | ||
} |