10
10
11
11
import ql
12
12
13
+ AstNode getASubExpression ( Select sel ) {
14
+ result = sel .getExpr ( _)
15
+ or
16
+ result = getASubExpression ( sel ) .getAChild ( )
17
+ }
18
+
13
19
/** Gets the `index`th part of the select statement. */
14
20
private AstNode getSelectPart ( Select sel , int index ) {
15
21
result =
16
22
rank [ index ] ( AstNode n , Location loc |
17
23
(
18
- n . getParent * ( ) = sel . getExpr ( _ ) and loc = n .getLocation ( )
24
+ n = getASubExpression ( sel ) and loc = n .getLocation ( )
19
25
or
20
26
// the strings are behind a predicate call.
21
- exists ( Call c , Predicate target |
22
- c .getParent * ( ) = sel .getExpr ( _) and loc = c .getLocation ( )
23
- |
27
+ exists ( Call c , Predicate target | c = getASubExpression ( sel ) and loc = c .getLocation ( ) |
24
28
c .getTarget ( ) = target and
25
29
(
26
30
target .getBody ( ) .( ComparisonFormula ) .getAnOperand ( ) = n
@@ -30,6 +34,14 @@ private AstNode getSelectPart(Select sel, int index) {
30
34
)
31
35
)
32
36
)
37
+ or
38
+ // the string is a variable that is assigned in the `where` clause.
39
+ exists ( VarAccess v , ComparisonFormula comp , String str |
40
+ v = getASubExpression ( sel ) and
41
+ loc = v .getLocation ( ) and
42
+ comp .hasOperands ( v .getDeclaration ( ) .getAnAccess ( ) , str ) and
43
+ n = str
44
+ )
33
45
)
34
46
|
35
47
n
@@ -52,7 +64,7 @@ private AstNode getSelectPart(Select sel, int index) {
52
64
String shouldHaveFullStop ( Select sel ) {
53
65
result =
54
66
max ( AstNode str , int i |
55
- str .getParent + ( ) = sel .getExpr ( 1 ) and str = getSelectPart ( sel , i )
67
+ str .getParent * ( ) = sel .getMessage ( ) and str = getSelectPart ( sel , i )
56
68
|
57
69
str order by i
58
70
) and
@@ -73,7 +85,7 @@ String shouldHaveFullStop(Select sel) {
73
85
String shouldStartCapital ( Select sel ) {
74
86
result =
75
87
min ( AstNode str , int i |
76
- str .getParent + ( ) = sel .getExpr ( 1 ) and str = getSelectPart ( sel , i )
88
+ str .getParent * ( ) = sel .getMessage ( ) and str = getSelectPart ( sel , i )
77
89
|
78
90
str order by i
79
91
) and
@@ -164,6 +176,14 @@ String wrongFlowsPhrase(Select sel, string kind) {
164
176
)
165
177
}
166
178
179
+ /**
180
+ * Gets a string element that contains double whitespace.
181
+ */
182
+ String doubleWhitespace ( Select sel ) {
183
+ result = getSelectPart ( sel , _) and
184
+ result .getValue ( ) .regexpMatch ( ".*\\s\\s.*" )
185
+ }
186
+
167
187
from AstNode node , string msg
168
188
where
169
189
not node .getLocation ( ) .getFile ( ) .getAbsolutePath ( ) .matches ( "%/test/%" ) and
@@ -194,5 +214,8 @@ where
194
214
or
195
215
node = wrongFlowsPhrase ( _, "taint" ) and
196
216
msg = "Use \"depends on\" instead of \"flows to\" in taint tracking queries."
217
+ or
218
+ node = doubleWhitespace ( _) and
219
+ msg = "Avoid using double whitespace in alert messages."
197
220
)
198
221
select node , msg
0 commit comments