Skip to content

Commit c1827cf

Browse files
committed
QL: Add test for getAStringValue
1 parent 4c72c31 commit c1827cf

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
predicate isLeft(string s) { none() }
2+
3+
predicate isRight(string s) { none() }
4+
5+
predicate disjunct() {
6+
exists(string x |
7+
x = "left_1" and
8+
isLeft(x) // $ getAStringValue=left_1
9+
or
10+
x = "right_1" and
11+
isRight(x) // $ getAStringValue=right_1
12+
)
13+
}
14+
15+
string sourceLeft2() { result = "left_2" }
16+
17+
predicate sinkLeft2(string x) {
18+
isLeft(x) // $ getAStringValue=left_2
19+
}
20+
21+
string sourceRight2() { result = "right_2" }
22+
23+
predicate sinkRight2(string x) {
24+
isRight(x) // $ getAStringValue=right_2
25+
}
26+
27+
predicate disjunctViaCall() {
28+
exists(string x |
29+
x = sourceLeft2() and
30+
sinkLeft2(x) // $ getAStringValue=left_2
31+
or
32+
x = sourceRight2() and
33+
sinkRight2(x) // $ getAStringValue=right_2
34+
)
35+
}
36+
37+
predicate distribute() {
38+
exists(string x |
39+
x = "left_3"
40+
or
41+
x = "right_3"
42+
|
43+
isLeft(x) // $ getAStringValue=left_3 getAStringValue=right_3
44+
or
45+
isRight(x) // $ getAStringValue=left_3 getAStringValue=right_3
46+
)
47+
}
48+
49+
predicate distributeSet() {
50+
exists(string x | x = ["left_4", "right_4"] |
51+
isLeft(x) // $ getAStringValue=left_4 getAStringValue=right_4
52+
or
53+
isRight(x) // $ getAStringValue=left_4 getAStringValue=right_4
54+
)
55+
}
56+
57+
predicate noFlowBackOut() {
58+
exists(string x |
59+
isLeft(x) // no value
60+
)
61+
}
62+
63+
class StringClass extends string {
64+
StringClass() { this = "StringClass" }
65+
}
66+
67+
class FieldClass extends int {
68+
StringClass field;
69+
70+
FieldClass() { this = 0 }
71+
72+
StringClass getField() { result = field }
73+
}
74+
75+
predicate isStringClass(string s) { none() }
76+
77+
predicate test() {
78+
isStringClass(any(FieldClass f).getField()) // $ getAStringValue=StringClass
79+
}

ql/ql/test/dataflow/getAStringValue/getAStringValue.expected

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import ql
2+
import codeql_ql.dataflow.DataFlow
3+
import TestUtilities.InlineExpectationsTest
4+
5+
class GetAStringValueTest extends InlineExpectationsTest {
6+
GetAStringValueTest() { this = "getAStringValue" }
7+
8+
override string getARelevantTag() { result = "getAStringValue" }
9+
10+
override predicate hasActualResult(Location location, string element, string tag, string value) {
11+
exists(Expr e |
12+
e = any(Call c).getAnArgument() and
13+
tag = "getAStringValue" and
14+
value = superNode(e).getAStringValue() and
15+
location = e.getLocation() and
16+
element = e.toString()
17+
)
18+
}
19+
}

0 commit comments

Comments
 (0)