@@ -21,31 +21,19 @@ private predicate predictableInstruction(Instruction instr) {
2121 predictableInstruction ( instr .( UnaryInstruction ) .getUnary ( ) )
2222}
2323
24+ private DataFlow:: Node getNodeForSource ( Expr source ) {
25+ isUserInput ( source , _) and
26+ (
27+ result = DataFlow:: exprNode ( source )
28+ or
29+ result = DataFlow:: definitionByReferenceNode ( source )
30+ )
31+ }
32+
2433private class DefaultTaintTrackingCfg extends DataFlow:: Configuration {
2534 DefaultTaintTrackingCfg ( ) { this = "DefaultTaintTrackingCfg" }
2635
27- override predicate isSource ( DataFlow:: Node source ) {
28- exists ( CallInstruction ci , WriteSideEffectInstruction wsei |
29- userInputArgument ( ci .getConvertedResultExpression ( ) , wsei .getIndex ( ) ) and
30- source .asInstruction ( ) = wsei and
31- wsei .getPrimaryInstruction ( ) = ci
32- )
33- or
34- userInputReturned ( source .asExpr ( ) )
35- or
36- isUserInput ( source .asExpr ( ) , _)
37- or
38- source .asExpr ( ) instanceof EnvironmentRead
39- or
40- source
41- .asInstruction ( )
42- .( LoadInstruction )
43- .getSourceAddress ( )
44- .( VariableAddressInstruction )
45- .getASTVariable ( )
46- .hasName ( "argv" ) and
47- source .asInstruction ( ) .getEnclosingFunction ( ) .hasGlobalName ( "main" )
48- }
36+ override predicate isSource ( DataFlow:: Node source ) { source = getNodeForSource ( _) }
4937
5038 override predicate isSink ( DataFlow:: Node sink ) { any ( ) }
5139
@@ -59,7 +47,7 @@ private class DefaultTaintTrackingCfg extends DataFlow::Configuration {
5947private class ToGlobalVarTaintTrackingCfg extends DataFlow:: Configuration {
6048 ToGlobalVarTaintTrackingCfg ( ) { this = "GlobalVarTaintTrackingCfg" }
6149
62- override predicate isSource ( DataFlow:: Node source ) { isUserInput ( source . asExpr ( ) , _) }
50+ override predicate isSource ( DataFlow:: Node source ) { source = getNodeForSource ( _) }
6351
6452 override predicate isSink ( DataFlow:: Node sink ) {
6553 exists ( GlobalOrNamespaceVariable gv | writesVariable ( sink .asInstruction ( ) , gv ) )
@@ -306,10 +294,7 @@ private Element adjustedSink(DataFlow::Node sink) {
306294
307295predicate tainted ( Expr source , Element tainted ) {
308296 exists ( DefaultTaintTrackingCfg cfg , DataFlow:: Node sink |
309- cfg .hasFlow ( DataFlow:: exprNode ( source ) , sink )
310- or
311- cfg .hasFlow ( DataFlow:: definitionByReferenceNode ( source ) , sink )
312- |
297+ cfg .hasFlow ( getNodeForSource ( source ) , sink ) and
313298 tainted = adjustedSink ( sink )
314299 )
315300}
@@ -322,7 +307,7 @@ predicate taintedIncludingGlobalVars(Expr source, Element tainted, string global
322307 ToGlobalVarTaintTrackingCfg toCfg , FromGlobalVarTaintTrackingCfg fromCfg , DataFlow:: Node store ,
323308 GlobalOrNamespaceVariable global , DataFlow:: Node load , DataFlow:: Node sink
324309 |
325- toCfg .hasFlow ( DataFlow :: exprNode ( source ) , store ) and
310+ toCfg .hasFlow ( getNodeForSource ( source ) , store ) and
326311 store
327312 .asInstruction ( )
328313 .( StoreInstruction )
0 commit comments