mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Add exclusions to reduce FP
Predicate parameters that have a database type are excluded. Also, uses of the exists variable in an agreggation or another quantifier are excluded.
This commit is contained in:
@@ -10,12 +10,22 @@
|
||||
|
||||
import ql
|
||||
|
||||
class AggregateOrForQuantifier extends AstNode {
|
||||
AggregateOrForQuantifier() {
|
||||
this instanceof FullAggregate or this instanceof Forex or this instanceof Forall
|
||||
}
|
||||
}
|
||||
|
||||
from VarDecl existsArgument, VarAccess use
|
||||
where
|
||||
existsArgument = any(Exists e).getAnArgument() and
|
||||
use = unique( | | existsArgument.getAnAccess()) and
|
||||
exists(Call c, int argPos | c.getArgument(argPos) = use |
|
||||
existsArgument.getType() = c.getTarget().getParameterType(argPos).getASuperType*()
|
||||
)
|
||||
exists(Call c, int argPos, Type paramType |
|
||||
c.getArgument(argPos) = use and paramType = c.getTarget().getParameterType(argPos)
|
||||
|
|
||||
existsArgument.getType() = paramType.getASuperType*() and
|
||||
not paramType instanceof DatabaseType
|
||||
) and
|
||||
not use.getParent*() instanceof AggregateOrForQuantifier
|
||||
select existsArgument, "This exists variable can be omitted by using a don't-care expression $@.",
|
||||
use, "in this argument"
|
||||
|
||||
@@ -1 +1 @@
|
||||
| Test.qll:10:10:10:14 | i | This exists variable can be omitted by using a don't-care expression $@. | Test.qll:10:29:10:29 | i | in this argument |
|
||||
| Test.qll:18:10:18:14 | i | This exists variable can be omitted by using a don't-care expression $@. | Test.qll:18:29:18:29 | i | in this argument |
|
||||
|
||||
@@ -2,10 +2,18 @@ predicate aPredicate(int i) { none() }
|
||||
|
||||
predicate anotherPredicate(int i) { none() }
|
||||
|
||||
predicate yetAnotherPredicate(int i, int y) { none() }
|
||||
|
||||
predicate dbTypePredicate(@location l) { none() }
|
||||
|
||||
class SmallInt extends int {
|
||||
SmallInt() { this = [0 .. 10] }
|
||||
}
|
||||
|
||||
class Location extends @location {
|
||||
string toString() { result = "" }
|
||||
}
|
||||
|
||||
predicate test() {
|
||||
exists(int i | aPredicate(i)) // BAD
|
||||
or
|
||||
@@ -15,5 +23,13 @@ predicate test() {
|
||||
or
|
||||
exists(int i | aPredicate(i) and exists(int i2 | i = i2)) // GOOD
|
||||
or
|
||||
exists(int i | count(int y | yetAnotherPredicate(i, y)) > 0) // GOOD
|
||||
or
|
||||
exists(int i | forex(int y | yetAnotherPredicate(i, y))) // GOOD
|
||||
or
|
||||
exists(int i | forall(int y | yetAnotherPredicate(i, y))) // GOOD
|
||||
or
|
||||
exists(SmallInt i | aPredicate(i)) // GOOD
|
||||
or
|
||||
exists(Location l | dbTypePredicate(l)) // GOOD
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user