@@ -21,31 +21,19 @@ private predicate predictableInstruction(Instruction instr) {
21
21
predictableInstruction ( instr .( UnaryInstruction ) .getUnary ( ) )
22
22
}
23
23
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
+
24
33
private class DefaultTaintTrackingCfg extends DataFlow:: Configuration {
25
34
DefaultTaintTrackingCfg ( ) { this = "DefaultTaintTrackingCfg" }
26
35
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 ( _) }
49
37
50
38
override predicate isSink ( DataFlow:: Node sink ) { any ( ) }
51
39
@@ -59,7 +47,7 @@ private class DefaultTaintTrackingCfg extends DataFlow::Configuration {
59
47
private class ToGlobalVarTaintTrackingCfg extends DataFlow:: Configuration {
60
48
ToGlobalVarTaintTrackingCfg ( ) { this = "GlobalVarTaintTrackingCfg" }
61
49
62
- override predicate isSource ( DataFlow:: Node source ) { isUserInput ( source . asExpr ( ) , _) }
50
+ override predicate isSource ( DataFlow:: Node source ) { source = getNodeForSource ( _) }
63
51
64
52
override predicate isSink ( DataFlow:: Node sink ) {
65
53
exists ( GlobalOrNamespaceVariable gv | writesVariable ( sink .asInstruction ( ) , gv ) )
@@ -306,10 +294,7 @@ private Element adjustedSink(DataFlow::Node sink) {
306
294
307
295
predicate tainted ( Expr source , Element tainted ) {
308
296
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
313
298
tainted = adjustedSink ( sink )
314
299
)
315
300
}
@@ -322,7 +307,7 @@ predicate taintedIncludingGlobalVars(Expr source, Element tainted, string global
322
307
ToGlobalVarTaintTrackingCfg toCfg , FromGlobalVarTaintTrackingCfg fromCfg , DataFlow:: Node store ,
323
308
GlobalOrNamespaceVariable global , DataFlow:: Node load , DataFlow:: Node sink
324
309
|
325
- toCfg .hasFlow ( DataFlow :: exprNode ( source ) , store ) and
310
+ toCfg .hasFlow ( getNodeForSource ( source ) , store ) and
326
311
store
327
312
.asInstruction ( )
328
313
.( StoreInstruction )
0 commit comments