99 */
1010import semmle.code.cpp.dataflow.DataFlow
1111import semmle.code.cpp.dataflow.DataFlow2
12+ import semmle.code.cpp.models.interfaces.DataFlow
13+ import semmle.code.cpp.models.interfaces.Taint
1214
1315module TaintTracking {
1416
@@ -187,6 +189,9 @@ module TaintTracking {
187189 exprFrom .( PostfixCrementOperation )
188190 )
189191 )
192+ or
193+ // Taint can flow through modeled functions
194+ exprToDefinitionByReferenceStep ( nodeFrom .asExpr ( ) , nodeTo .asDefiningArgument ( ) )
190195 }
191196
192197 /**
@@ -226,4 +231,35 @@ module TaintTracking {
226231 e instanceof AlignofOperator
227232 }
228233
229- }
234+ private predicate exprToDefinitionByReferenceStep ( Expr exprIn , Expr argOut ) {
235+ exists ( DataFlowFunction f , Call call , FunctionOutput outModel , int argOutIndex |
236+ call .getTarget ( ) = f and
237+ argOut = call .getArgument ( argOutIndex ) and
238+ outModel .isOutParameterPointer ( argOutIndex ) and
239+ exists ( int argInIndex , FunctionInput inModel |
240+ f .hasDataFlow ( inModel , outModel )
241+ |
242+ inModel .isInParameterPointer ( argInIndex ) and
243+ exprIn = call .getArgument ( argInIndex )
244+ )
245+ )
246+ or
247+ exists ( TaintFunction f , Call call , FunctionOutput outModel , int argOutIndex |
248+ call .getTarget ( ) = f and
249+ argOut = call .getArgument ( argOutIndex ) and
250+ outModel .isOutParameterPointer ( argOutIndex ) and
251+ exists ( int argInIndex , FunctionInput inModel |
252+ f .hasTaintFlow ( inModel , outModel )
253+ |
254+ inModel .isInParameterPointer ( argInIndex ) and
255+ exprIn = call .getArgument ( argInIndex )
256+ or
257+ inModel .isInParameterPointer ( argInIndex ) and
258+ call .passesByReference ( argInIndex , exprIn )
259+ or
260+ inModel .isInParameter ( argInIndex ) and
261+ exprIn = call .getArgument ( argInIndex )
262+ )
263+ )
264+ }
265+ }
0 commit comments