@@ -348,6 +348,16 @@ private Element adjustedSink(DataFlow::Node sink) {
348348 result .( AssignOperation ) .getAnOperand ( ) = sink .asExpr ( )
349349}
350350
351+ /**
352+ * Holds if `tainted` may contain taint from `source`.
353+ *
354+ * A tainted expression is either directly user input, or is
355+ * computed from user input in a way that users can probably
356+ * control the exact output of the computation.
357+ *
358+ * This doesn't include data flow through global variables.
359+ * If you need that you must call `taintedIncludingGlobalVars`.
360+ */
351361cached
352362predicate tainted ( Expr source , Element tainted ) {
353363 exists ( DefaultTaintTrackingCfg cfg , DataFlow:: Node sink |
@@ -356,6 +366,21 @@ predicate tainted(Expr source, Element tainted) {
356366 )
357367}
358368
369+ /**
370+ * Holds if `tainted` may contain taint from `source`, where the taint passed
371+ * through a global variable named `globalVar`.
372+ *
373+ * A tainted expression is either directly user input, or is
374+ * computed from user input in a way that users can probably
375+ * control the exact output of the computation.
376+ *
377+ * This version gives the same results as tainted but also includes
378+ * data flow through global variables.
379+ *
380+ * The parameter `globalVar` is the qualified name of the last global variable
381+ * used to move the value from source to tainted. If the taint did not pass
382+ * through a global variable, then `globalVar = ""`.
383+ */
359384cached
360385predicate taintedIncludingGlobalVars ( Expr source , Element tainted , string globalVar ) {
361386 tainted ( source , tainted ) and
@@ -373,8 +398,26 @@ predicate taintedIncludingGlobalVars(Expr source, Element tainted, string global
373398 )
374399}
375400
401+ /**
402+ * Gets the global variable whose qualified name is `id`. Use this predicate
403+ * together with `taintedIncludingGlobalVars`. Example:
404+ *
405+ * ```
406+ * exists(string varName |
407+ * taintedIncludingGlobalVars(source, tainted, varName) and
408+ * var = globalVarFromId(varName)
409+ * )
410+ * ```
411+ */
376412GlobalOrNamespaceVariable globalVarFromId ( string id ) { id = result .getQualifiedName ( ) }
377413
414+ /**
415+ * Resolve potential target function(s) for `call`.
416+ *
417+ * If `call` is a call through a function pointer (`ExprCall`) or
418+ * targets a virtual method, simple data flow analysis is performed
419+ * in order to identify target(s).
420+ */
378421Function resolveCall ( Call call ) {
379422 exists ( CallInstruction callInstruction |
380423 callInstruction .getAST ( ) = call and
0 commit comments