mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
Merge pull request #6372 from geoffw0/uncontrolledarith
This commit is contained in:
@@ -74,8 +74,15 @@ private class RandS extends RandomFunction {
|
||||
|
||||
predicate missingGuard(VariableAccess va, string effect) {
|
||||
exists(Operation op | op.getAnOperand() = va |
|
||||
missingGuardAgainstUnderflow(op, va) and effect = "underflow"
|
||||
// underflow - random numbers are usually non-negative, so underflow is
|
||||
// only likely if the type is unsigned. Multiplication is also unlikely to
|
||||
// cause underflow of a non-negative number.
|
||||
missingGuardAgainstUnderflow(op, va) and
|
||||
effect = "underflow" and
|
||||
op.getUnspecifiedType().(IntegralType).isUnsigned() and
|
||||
not op instanceof MulExpr
|
||||
or
|
||||
// overflow
|
||||
missingGuardAgainstOverflow(op, va) and effect = "overflow"
|
||||
)
|
||||
}
|
||||
@@ -108,6 +115,9 @@ class UncontrolledArithConfiguration extends TaintTracking::Configuration {
|
||||
op instanceof BitwiseAndExpr or
|
||||
op instanceof ComplementExpr
|
||||
).getAnOperand*()
|
||||
or
|
||||
// block unintended flow to pointers
|
||||
node.asExpr().getUnspecifiedType() instanceof PointerType
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user