@@ -15,27 +15,31 @@ import cpp
15
15
import semmle.code.cpp.security.TaintTracking
16
16
import TaintedWithPath
17
17
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
21
25
tainted .getUnspecifiedType ( ) instanceof IntegralType
22
26
}
23
27
24
28
class TaintedAllocationSizeConfiguration extends TaintTrackingConfiguration {
25
- override predicate isSink ( Element tainted ) { taintedChild ( _, tainted ) }
29
+ override predicate isSink ( Element tainted ) { allocSink ( _, tainted ) }
26
30
}
27
31
28
32
predicate taintedAllocSize (
29
- Expr e , Expr source , PathNode sourceNode , PathNode sinkNode , string taintCause
33
+ Expr source , Expr alloc , PathNode sourceNode , PathNode sinkNode , string taintCause
30
34
) {
31
35
isUserInput ( source , taintCause ) and
32
36
exists ( Expr tainted |
33
- taintedChild ( e , tainted ) and
37
+ allocSink ( alloc , tainted ) and
34
38
taintedWithPath ( source , tainted , sourceNode , sinkNode )
35
39
)
36
40
}
37
41
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" ,
41
45
source , "user input (" + taintCause + ")"
0 commit comments