Skip to content

Commit c5592a1

Browse files
committed
C++: New experimental query.
1 parent ec573b5 commit c5592a1

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @name Multiplication result may overflow and be used in allocation
3+
* @description TODO
4+
* @kind path-problem
5+
* @problem.severity TODO
6+
* @precision TODO
7+
* @tags security
8+
* correctness
9+
* external/cwe/cwe-190
10+
* external/cwe/cwe-128
11+
* @id cpp/multiplication-overflow-in-alloc
12+
*/
13+
14+
import cpp
15+
import semmle.code.cpp.models.interfaces.Allocation
16+
import semmle.code.cpp.dataflow.DataFlow
17+
import DataFlow::PathGraph
18+
19+
class MultToAllocConfig extends DataFlow::Configuration {
20+
MultToAllocConfig() { this = "MultToAllocConfig" }
21+
22+
override predicate isSource(DataFlow::Node node) {
23+
// a multiplication of two non-constant expressions
24+
exists(MulExpr me |
25+
me = node.asExpr() and
26+
forall(Expr e | e = me.getAnOperand() | not exists(e.getValue()))
27+
)
28+
}
29+
30+
override predicate isSink(DataFlow::Node node) {
31+
// something that affects an allocation size
32+
node.asExpr() = any(AllocationExpr ae).getSizeExpr().getAChild*()
33+
}
34+
}
35+
36+
string describe(DataFlow::PathNode n) {
37+
result = n.getNode().asExpr().getEnclosingFunction().getName()
38+
}
39+
40+
from MultToAllocConfig config, DataFlow::PathNode source, DataFlow::PathNode sink
41+
where config.hasFlowPath(source, sink)
42+
select sink, source, sink, "$@ in " + concat(describe(source), ", "), source, "here"

0 commit comments

Comments
 (0)