Skip to content

Commit ba3a8d0

Browse files
committed
C++: Improve naming and QLDoc.
1 parent a7979fd commit ba3a8d0

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

cpp/ql/src/Security/CWE/CWE-190/TaintedAllocationSize.ql

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,31 @@ import cpp
1515
import semmle.code.cpp.security.TaintTracking
1616
import TaintedWithPath
1717

18-
predicate taintedChild(Expr e, Expr tainted) {
19-
isAllocationExpr(e) and
20-
tainted = e.getAChild() and
18+
/**
19+
* Holds if `alloc` is an allocation, and `tainted` is a child of it that is a
20+
* taint sink.
21+
*/
22+
predicate allocSink(Expr alloc, Expr tainted) {
23+
isAllocationExpr(alloc) and
24+
tainted = alloc.getAChild() and
2125
tainted.getUnspecifiedType() instanceof IntegralType
2226
}
2327

2428
class TaintedAllocationSizeConfiguration extends TaintTrackingConfiguration {
25-
override predicate isSink(Element tainted) { taintedChild(_, tainted) }
29+
override predicate isSink(Element tainted) { allocSink(_, tainted) }
2630
}
2731

2832
predicate taintedAllocSize(
29-
Expr e, Expr source, PathNode sourceNode, PathNode sinkNode, string taintCause
33+
Expr source, Expr alloc, PathNode sourceNode, PathNode sinkNode, string taintCause
3034
) {
3135
isUserInput(source, taintCause) and
3236
exists(Expr tainted |
33-
taintedChild(e, tainted) and
37+
allocSink(alloc, tainted) and
3438
taintedWithPath(source, tainted, sourceNode, sinkNode)
3539
)
3640
}
3741

38-
from Expr e, Expr source, PathNode sourceNode, PathNode sinkNode, string taintCause
39-
where taintedAllocSize(e, source, sourceNode, sinkNode, taintCause)
40-
select e, sourceNode, sinkNode, "This allocation size is derived from $@ and might overflow",
42+
from Expr source, Expr alloc, PathNode sourceNode, PathNode sinkNode, string taintCause
43+
where taintedAllocSize(source, alloc, sourceNode, sinkNode, taintCause)
44+
select alloc, sourceNode, sinkNode, "This allocation size is derived from $@ and might overflow",
4145
source, "user input (" + taintCause + ")"

0 commit comments

Comments
 (0)