@@ -25,6 +25,20 @@ abstract class ConsistencyConfiguration extends string {
25
25
File getAFile ( ) { none ( ) }
26
26
}
27
27
28
+ /**
29
+ * A string that either equals a `ConsistencyConfiguration`, or the empty string if no such configuration exists.
30
+ *
31
+ * Is user internally to match a configuration or lack thereof.
32
+ */
33
+ final private class Conf extends string {
34
+ Conf ( ) {
35
+ this instanceof ConsistencyConfiguration
36
+ or
37
+ not exists ( ConsistencyConfiguration c ) and
38
+ this = ""
39
+ }
40
+ }
41
+
28
42
/**
29
43
* A line-comment that asserts whether a result exists at that line or not.
30
44
* Can optionally include `[INCONSISTENCY]` to indicate that a consistency issue is expected at the location
@@ -54,30 +68,31 @@ private class AssertionComment extends LineComment {
54
68
private DataFlow:: Node getASink ( ) { exists ( DataFlow:: Configuration cfg | cfg .hasFlow ( _, result ) ) }
55
69
56
70
/**
57
- * Gets all the alerts for consistency consistency checking.
71
+ * Gets all the alerts for consistency consistency checking from a configuration `conf` .
58
72
*/
59
- private DataFlow:: Node alerts ( ) {
60
- result = any ( ConsistencyConfiguration res ) .getAnAlert ( )
73
+ private DataFlow:: Node alerts ( Conf conf ) {
74
+ result = any ( ConsistencyConfiguration res | res = conf ) .getAnAlert ( )
61
75
or
62
76
not exists ( ConsistencyConfiguration r ) and
63
- result = getASink ( )
77
+ result = getASink ( ) and
78
+ conf = ""
64
79
}
65
80
66
81
/**
67
- * Gets an alert in `file` at `line`.
82
+ * Gets an alert in `file` at `line` for configuration `conf` .
68
83
* The `line` can be either the first or the last line of the alert.
69
84
* And if no expression exists at `line`, then an alert on the next line is used.
70
85
*/
71
- private DataFlow:: Node getAlert ( File file , int line ) {
72
- result = alerts ( ) and
86
+ private DataFlow:: Node getAlert ( File file , int line , Conf conf ) {
87
+ result = alerts ( conf ) and
73
88
result .getFile ( ) = file and
74
89
( result .hasLocationInfo ( _, _, _, line , _) or result .hasLocationInfo ( _, line , _, _, _) )
75
90
or
76
91
// The comment can be right above the result, so an alert also counts for the line above.
77
92
not exists ( Expr e |
78
93
e .getFile ( ) = file and [ e .getLocation ( ) .getStartLine ( ) , e .getLocation ( ) .getEndLine ( ) ] = line
79
94
) and
80
- result = alerts ( ) and
95
+ result = alerts ( conf ) and
81
96
result .getFile ( ) = file and
82
97
result .hasLocationInfo ( _, line + 1 , _, _, _)
83
98
}
@@ -91,66 +106,70 @@ private AssertionComment getComment(File file, int line) {
91
106
}
92
107
93
108
/**
94
- * Holds if there is a false positive in `file` at `line`
109
+ * Holds if there is a false positive in `file` at `line` for configuration `conf`.
95
110
*/
96
- private predicate falsePositive ( File file , int line , AssertionComment comment ) {
97
- exists ( getAlert ( file , line ) ) and
111
+ private predicate falsePositive ( File file , int line , AssertionComment comment , Conf conf ) {
112
+ exists ( getAlert ( file , line , conf ) ) and
98
113
comment = getComment ( file , line ) and
99
114
not comment .shouldHaveAlert ( )
100
115
}
101
116
102
117
/**
103
- * Holds if there is a false negative in `file` at `line`
118
+ * Holds if there is a false negative in `file` at `line` for configuration `conf`.
104
119
*/
105
- private predicate falseNegative ( File file , int line , AssertionComment comment ) {
106
- not exists ( getAlert ( file , line ) ) and
120
+ private predicate falseNegative ( File file , int line , AssertionComment comment , Conf conf ) {
121
+ not exists ( getAlert ( file , line , conf ) ) and
107
122
comment = getComment ( file , line ) and
108
123
comment .shouldHaveAlert ( )
109
124
}
110
125
111
126
/**
112
- * Gets a file that should be included for consistency checking.
127
+ * Gets a file that should be included for consistency checking for configuration `conf` .
113
128
*/
114
- private File getATestFile ( ) {
129
+ private File getATestFile ( string conf ) {
115
130
not exists ( any ( ConsistencyConfiguration res ) .getAFile ( ) ) and
116
- result = any ( LineComment comment ) .getFile ( )
131
+ result = any ( LineComment comment ) .getFile ( ) and
132
+ conf = ""
117
133
or
118
- result = any ( ConsistencyConfiguration res ) .getAFile ( )
134
+ result = any ( ConsistencyConfiguration res | res = conf ) .getAFile ( )
119
135
}
120
136
121
137
/**
122
- * Gets a description of the configuration that has a sink in `file` at `line`.
138
+ * Gets a description of the configuration that has a sink in `file` at `line` for configuration `conf` .
123
139
* Or the empty string
124
140
*/
125
141
bindingset [ file, line]
126
- private string getSinkDescription ( File file , int line ) {
127
- not exists ( DataFlow:: Configuration c | c .hasFlow ( _, getAlert ( file , line ) ) ) and result = ""
142
+ private string getSinkDescription ( File file , int line , Conf conf ) {
143
+ not exists ( DataFlow:: Configuration c | c .hasFlow ( _, getAlert ( file , line , conf ) ) ) and
144
+ result = ""
128
145
or
129
- exists ( DataFlow:: Configuration c | c .hasFlow ( _, getAlert ( file , line ) ) | result = " for " + c )
146
+ exists ( DataFlow:: Configuration c | c .hasFlow ( _, getAlert ( file , line , conf ) ) |
147
+ result = " for " + c
148
+ )
130
149
}
131
150
132
151
/**
133
- * Holds if there is a consistency-issue at `location` with description `msg`.
152
+ * Holds if there is a consistency-issue at `location` with description `msg` for configuration `conf` .
134
153
* The consistency issue an unexpected false positive/negative.
135
154
* Or that false positive/negative was expected, and none were found.
136
155
*/
137
- query predicate consistencyIssue ( string location , string msg , string commentText ) {
156
+ query predicate consistencyIssue ( string location , string msg , string commentText , Conf conf ) {
138
157
exists ( File file , int line |
139
- file = getATestFile ( ) and location = file .getRelativePath ( ) + ":" + line
158
+ file = getATestFile ( conf ) and location = file .getRelativePath ( ) + ":" + line
140
159
|
141
160
exists ( AssertionComment comment |
142
161
comment .getText ( ) .trim ( ) = commentText and comment = getComment ( file , line )
143
162
|
144
- falsePositive ( file , line , comment ) and
163
+ falsePositive ( file , line , comment , conf ) and
145
164
not comment .expectConsistencyError ( ) and
146
- msg = "did not expected an alert, but found an alert" + getSinkDescription ( file , line )
165
+ msg = "did not expect an alert, but found an alert" + getSinkDescription ( file , line , conf )
147
166
or
148
- falseNegative ( file , line , comment ) and
167
+ falseNegative ( file , line , comment , conf ) and
149
168
not comment .expectConsistencyError ( ) and
150
169
msg = "expected an alert, but found none"
151
170
or
152
- not falsePositive ( file , line , comment ) and
153
- not falseNegative ( file , line , comment ) and
171
+ not falsePositive ( file , line , comment , conf ) and
172
+ not falseNegative ( file , line , comment , conf ) and
154
173
comment .expectConsistencyError ( ) and
155
174
msg = "expected consistency issue, but found no such issue (" + comment .getText ( ) .trim ( ) + ")"
156
175
)
0 commit comments