@@ -25,6 +25,20 @@ abstract class ConsistencyConfiguration extends string {
2525 File getAFile ( ) { none ( ) }
2626}
2727
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+
2842/**
2943 * A line-comment that asserts whether a result exists at that line or not.
3044 * Can optionally include `[INCONSISTENCY]` to indicate that a consistency issue is expected at the location
@@ -54,30 +68,31 @@ private class AssertionComment extends LineComment {
5468private DataFlow:: Node getASink ( ) { exists ( DataFlow:: Configuration cfg | cfg .hasFlow ( _, result ) ) }
5569
5670/**
57- * Gets all the alerts for consistency consistency checking.
71+ * Gets all the alerts for consistency consistency checking from a configuration `conf` .
5872 */
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 ( )
6175 or
6276 not exists ( ConsistencyConfiguration r ) and
63- result = getASink ( )
77+ result = getASink ( ) and
78+ conf = ""
6479}
6580
6681/**
67- * Gets an alert in `file` at `line`.
82+ * Gets an alert in `file` at `line` for configuration `conf` .
6883 * The `line` can be either the first or the last line of the alert.
6984 * And if no expression exists at `line`, then an alert on the next line is used.
7085 */
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
7388 result .getFile ( ) = file and
7489 ( result .hasLocationInfo ( _, _, _, line , _) or result .hasLocationInfo ( _, line , _, _, _) )
7590 or
7691 // The comment can be right above the result, so an alert also counts for the line above.
7792 not exists ( Expr e |
7893 e .getFile ( ) = file and [ e .getLocation ( ) .getStartLine ( ) , e .getLocation ( ) .getEndLine ( ) ] = line
7994 ) and
80- result = alerts ( ) and
95+ result = alerts ( conf ) and
8196 result .getFile ( ) = file and
8297 result .hasLocationInfo ( _, line + 1 , _, _, _)
8398}
@@ -91,66 +106,70 @@ private AssertionComment getComment(File file, int line) {
91106}
92107
93108/**
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`.
95110 */
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
98113 comment = getComment ( file , line ) and
99114 not comment .shouldHaveAlert ( )
100115}
101116
102117/**
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`.
104119 */
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
107122 comment = getComment ( file , line ) and
108123 comment .shouldHaveAlert ( )
109124}
110125
111126/**
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` .
113128 */
114- private File getATestFile ( ) {
129+ private File getATestFile ( string conf ) {
115130 not exists ( any ( ConsistencyConfiguration res ) .getAFile ( ) ) and
116- result = any ( LineComment comment ) .getFile ( )
131+ result = any ( LineComment comment ) .getFile ( ) and
132+ conf = ""
117133 or
118- result = any ( ConsistencyConfiguration res ) .getAFile ( )
134+ result = any ( ConsistencyConfiguration res | res = conf ) .getAFile ( )
119135}
120136
121137/**
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` .
123139 * Or the empty string
124140 */
125141bindingset [ 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 = ""
128145 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+ )
130149}
131150
132151/**
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` .
134153 * The consistency issue an unexpected false positive/negative.
135154 * Or that false positive/negative was expected, and none were found.
136155 */
137- query predicate consistencyIssue ( string location , string msg , string commentText ) {
156+ query predicate consistencyIssue ( string location , string msg , string commentText , Conf conf ) {
138157 exists ( File file , int line |
139- file = getATestFile ( ) and location = file .getRelativePath ( ) + ":" + line
158+ file = getATestFile ( conf ) and location = file .getRelativePath ( ) + ":" + line
140159 |
141160 exists ( AssertionComment comment |
142161 comment .getText ( ) .trim ( ) = commentText and comment = getComment ( file , line )
143162 |
144- falsePositive ( file , line , comment ) and
163+ falsePositive ( file , line , comment , conf ) and
145164 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 )
147166 or
148- falseNegative ( file , line , comment ) and
167+ falseNegative ( file , line , comment , conf ) and
149168 not comment .expectConsistencyError ( ) and
150169 msg = "expected an alert, but found none"
151170 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
154173 comment .expectConsistencyError ( ) and
155174 msg = "expected consistency issue, but found no such issue (" + comment .getText ( ) .trim ( ) + ")"
156175 )
0 commit comments