|
14 | 14 | import cpp |
15 | 15 | import semmle.code.cpp.security.TaintTracking |
16 | 16 |
|
17 | | -from Expr source, Expr tainted, BinaryArithmeticOperation oper, |
18 | | - SizeofOperator sizeof, string taintCause |
19 | | -where tainted(source, tainted) |
20 | | - and oper.getAnOperand() = tainted |
21 | | - and oper.getOperator() = "*" |
22 | | - and oper.getAnOperand() = sizeof |
23 | | - and oper != tainted |
24 | | - and sizeof.getValue().toInt() > 1 |
25 | | - and isUserInput(source, taintCause) |
26 | | -select |
27 | | - oper, "This allocation size is derived from $@ and might overflow", |
28 | | - source, "user input (" + taintCause + ")" |
| 17 | +predicate taintedAllocSize(Expr e, Expr source, string taintCause) { |
| 18 | + ( |
| 19 | + isAllocationExpr(e) or |
| 20 | + any(MulExpr me | me.getAChild() instanceof SizeofOperator) = e |
| 21 | + ) and |
| 22 | + exists(Expr tainted | |
| 23 | + tainted = e.getAChild() and |
| 24 | + tainted.getType().getUnspecifiedType() instanceof IntegralType and |
| 25 | + isUserInput(source, taintCause) and |
| 26 | + tainted(source, tainted) |
| 27 | + ) |
| 28 | +} |
| 29 | + |
| 30 | +from Expr e, Expr source, string taintCause |
| 31 | +where taintedAllocSize(e, source, taintCause) |
| 32 | +select e, "This allocation size is derived from $@ and might overflow", source, |
| 33 | + "user input (" + taintCause + ")" |
0 commit comments