@@ -15,27 +15,31 @@ import cpp
1515import semmle.code.cpp.security.TaintTracking
1616import 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
2428class TaintedAllocationSizeConfiguration extends TaintTrackingConfiguration {
25- override predicate isSink ( Element tainted ) { taintedChild ( _, tainted ) }
29+ override predicate isSink ( Element tainted ) { allocSink ( _, tainted ) }
2630}
2731
2832predicate 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