mirror of
https://github.com/github/codeql.git
synced 2026-04-14 03:24:06 +02:00
Exclude bounds-check arithmetic from tainted-arithmetic sinks
The java/tainted-arithmetic query now recognizes when an arithmetic expression appears directly as an operand of a comparison (e.g., `if (off + len > array.length)`). Such expressions are bounds checks, not vulnerable computations, and are excluded via the existing overflowIrrelevant predicate. Add test cases for bounds-checking patterns that should not be flagged.
This commit is contained in:
@@ -132,7 +132,21 @@ private predicate inBitwiseAnd(Expr exp) {
|
||||
/** Holds if overflow/underflow is irrelevant for this expression. */
|
||||
predicate overflowIrrelevant(Expr exp) {
|
||||
inBitwiseAnd(exp) or
|
||||
exp.getEnclosingCallable() instanceof HashCodeMethod
|
||||
exp.getEnclosingCallable() instanceof HashCodeMethod or
|
||||
arithmeticUsedInBoundsCheck(exp)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `exp` is an arithmetic expression used directly as an operand of a
|
||||
* comparison, indicating it is part of a bounds check rather than a vulnerable
|
||||
* computation. For example, in `if (off + len > array.length)`, the addition
|
||||
* is the bounds check itself.
|
||||
*/
|
||||
private predicate arithmeticUsedInBoundsCheck(ArithExpr exp) {
|
||||
exists(ComparisonExpr comp |
|
||||
comp.getAnOperand() = exp and
|
||||
comp.getEnclosingStmt() instanceof IfStmt
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user