@@ -43,12 +43,14 @@ import semmle.code.java.dataflow.ExternalFlow
43
43
import semmle.code.java.dataflow.TaintTracking
44
44
import TestUtilities.InlineExpectationsTest
45
45
46
+ private predicate defaultSource ( DataFlow:: Node src ) {
47
+ src .asExpr ( ) .( MethodAccess ) .getMethod ( ) .getName ( ) = [ "source" , "taint" ]
48
+ }
49
+
46
50
class DefaultValueFlowConf extends DataFlow:: Configuration {
47
51
DefaultValueFlowConf ( ) { this = "qltest:defaultValueFlowConf" }
48
52
49
- override predicate isSource ( DataFlow:: Node n ) {
50
- n .asExpr ( ) .( MethodAccess ) .getMethod ( ) .getName ( ) = [ "source" , "taint" ]
51
- }
53
+ override predicate isSource ( DataFlow:: Node n ) { defaultSource ( n ) }
52
54
53
55
override predicate isSink ( DataFlow:: Node n ) {
54
56
exists ( MethodAccess ma | ma .getMethod ( ) .hasName ( "sink" ) | n .asExpr ( ) = ma .getAnArgument ( ) )
@@ -60,9 +62,7 @@ class DefaultValueFlowConf extends DataFlow::Configuration {
60
62
class DefaultTaintFlowConf extends TaintTracking:: Configuration {
61
63
DefaultTaintFlowConf ( ) { this = "qltest:defaultTaintFlowConf" }
62
64
63
- override predicate isSource ( DataFlow:: Node n ) {
64
- n .asExpr ( ) .( MethodAccess ) .getMethod ( ) .getName ( ) = [ "source" , "taint" ]
65
- }
65
+ override predicate isSource ( DataFlow:: Node n ) { defaultSource ( n ) }
66
66
67
67
override predicate isSink ( DataFlow:: Node n ) {
68
68
exists ( MethodAccess ma | ma .getMethod ( ) .hasName ( "sink" ) | n .asExpr ( ) = ma .getAnArgument ( ) )
@@ -71,6 +71,11 @@ class DefaultTaintFlowConf extends TaintTracking::Configuration {
71
71
override int fieldFlowBranchLimit ( ) { result = 1000 }
72
72
}
73
73
74
+ private string getSourceArgString ( DataFlow:: Node src ) {
75
+ defaultSource ( src ) and
76
+ src .asExpr ( ) .( MethodAccess ) .getAnArgument ( ) .( StringLiteral ) .getValue ( ) = result
77
+ }
78
+
74
79
class InlineFlowTest extends InlineExpectationsTest {
75
80
InlineFlowTest ( ) { this = "HasFlowTest" }
76
81
@@ -81,7 +86,7 @@ class InlineFlowTest extends InlineExpectationsTest {
81
86
exists ( DataFlow:: Node src , DataFlow:: Node sink | getValueFlowConfig ( ) .hasFlow ( src , sink ) |
82
87
sink .getLocation ( ) = location and
83
88
element = sink .toString ( ) and
84
- value = ""
89
+ if exists ( getSourceArgString ( src ) ) then value = getSourceArgString ( src ) else value = ""
85
90
)
86
91
or
87
92
tag = "hasTaintFlow" and
@@ -90,7 +95,7 @@ class InlineFlowTest extends InlineExpectationsTest {
90
95
|
91
96
sink .getLocation ( ) = location and
92
97
element = sink .toString ( ) and
93
- value = ""
98
+ if exists ( getSourceArgString ( src ) ) then value = getSourceArgString ( src ) else value = ""
94
99
)
95
100
}
96
101
0 commit comments