Skip to content

Commit 6bbed9d

Browse files
committed
C++: Test layout.
1 parent cf9ab83 commit 6bbed9d

File tree

3 files changed

+57
-28
lines changed

3 files changed

+57
-28
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/ArithmeticUncontrolled/ArithmeticUncontrolled.expected

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ edges
88
| test.c:81:23:81:26 | call to rand | test.c:83:9:83:9 | r |
99
| test.c:99:14:99:19 | call to rand | test.c:100:5:100:5 | r |
1010
| test.c:125:13:125:16 | call to rand | test.c:127:9:127:9 | r |
11-
| test.c:148:22:148:25 | call to rand | test.c:150:9:150:9 | r |
12-
| test.c:148:22:148:27 | (unsigned int)... | test.c:150:9:150:9 | r |
11+
| test.c:155:22:155:25 | call to rand | test.c:157:9:157:9 | r |
12+
| test.c:155:22:155:27 | (unsigned int)... | test.c:157:9:157:9 | r |
1313
| test.cpp:8:9:8:12 | Store | test.cpp:24:11:24:18 | call to get_rand |
1414
| test.cpp:8:9:8:12 | call to rand | test.cpp:8:9:8:12 | Store |
1515
| test.cpp:13:2:13:15 | Chi [[]] | test.cpp:30:13:30:14 | get_rand2 output argument [[]] |
@@ -21,11 +21,11 @@ edges
2121
| test.cpp:30:13:30:14 | get_rand2 output argument [[]] | test.cpp:30:13:30:14 | Chi |
2222
| test.cpp:36:13:36:13 | Chi | test.cpp:37:7:37:7 | r |
2323
| test.cpp:36:13:36:13 | get_rand3 output argument [[]] | test.cpp:36:13:36:13 | Chi |
24-
| test.cpp:78:10:78:13 | call to rand | test.cpp:82:10:82:10 | x |
25-
| test.cpp:90:10:90:13 | call to rand | test.cpp:94:10:94:10 | x |
26-
| test.cpp:129:10:129:13 | call to rand | test.cpp:132:10:132:10 | b |
27-
| test.cpp:147:11:147:14 | call to rand | test.cpp:149:11:149:16 | (int)... |
28-
| test.cpp:147:11:147:14 | call to rand | test.cpp:149:16:149:16 | y |
24+
| test.cpp:86:10:86:13 | call to rand | test.cpp:90:10:90:10 | x |
25+
| test.cpp:98:10:98:13 | call to rand | test.cpp:102:10:102:10 | x |
26+
| test.cpp:151:10:151:13 | call to rand | test.cpp:154:10:154:10 | b |
27+
| test.cpp:169:11:169:14 | call to rand | test.cpp:171:11:171:16 | (int)... |
28+
| test.cpp:169:11:169:14 | call to rand | test.cpp:171:16:171:16 | y |
2929
nodes
3030
| test.c:18:13:18:16 | call to rand | semmle.label | call to rand |
3131
| test.c:21:17:21:17 | r | semmle.label | r |
@@ -43,9 +43,9 @@ nodes
4343
| test.c:100:5:100:5 | r | semmle.label | r |
4444
| test.c:125:13:125:16 | call to rand | semmle.label | call to rand |
4545
| test.c:127:9:127:9 | r | semmle.label | r |
46-
| test.c:148:22:148:25 | call to rand | semmle.label | call to rand |
47-
| test.c:148:22:148:27 | (unsigned int)... | semmle.label | (unsigned int)... |
48-
| test.c:150:9:150:9 | r | semmle.label | r |
46+
| test.c:155:22:155:25 | call to rand | semmle.label | call to rand |
47+
| test.c:155:22:155:27 | (unsigned int)... | semmle.label | (unsigned int)... |
48+
| test.c:157:9:157:9 | r | semmle.label | r |
4949
| test.cpp:8:9:8:12 | Store | semmle.label | Store |
5050
| test.cpp:8:9:8:12 | call to rand | semmle.label | call to rand |
5151
| test.cpp:13:2:13:15 | Chi [[]] | semmle.label | Chi [[]] |
@@ -60,15 +60,15 @@ nodes
6060
| test.cpp:36:13:36:13 | Chi | semmle.label | Chi |
6161
| test.cpp:36:13:36:13 | get_rand3 output argument [[]] | semmle.label | get_rand3 output argument [[]] |
6262
| test.cpp:37:7:37:7 | r | semmle.label | r |
63-
| test.cpp:78:10:78:13 | call to rand | semmle.label | call to rand |
64-
| test.cpp:82:10:82:10 | x | semmle.label | x |
65-
| test.cpp:90:10:90:13 | call to rand | semmle.label | call to rand |
66-
| test.cpp:94:10:94:10 | x | semmle.label | x |
67-
| test.cpp:129:10:129:13 | call to rand | semmle.label | call to rand |
68-
| test.cpp:132:10:132:10 | b | semmle.label | b |
69-
| test.cpp:147:11:147:14 | call to rand | semmle.label | call to rand |
70-
| test.cpp:149:11:149:16 | (int)... | semmle.label | (int)... |
71-
| test.cpp:149:16:149:16 | y | semmle.label | y |
63+
| test.cpp:86:10:86:13 | call to rand | semmle.label | call to rand |
64+
| test.cpp:90:10:90:10 | x | semmle.label | x |
65+
| test.cpp:98:10:98:13 | call to rand | semmle.label | call to rand |
66+
| test.cpp:102:10:102:10 | x | semmle.label | x |
67+
| test.cpp:151:10:151:13 | call to rand | semmle.label | call to rand |
68+
| test.cpp:154:10:154:10 | b | semmle.label | b |
69+
| test.cpp:169:11:169:14 | call to rand | semmle.label | call to rand |
70+
| test.cpp:171:11:171:16 | (int)... | semmle.label | (int)... |
71+
| test.cpp:171:16:171:16 | y | semmle.label | y |
7272
#select
7373
| test.c:21:17:21:17 | r | test.c:18:13:18:16 | call to rand | test.c:21:17:21:17 | r | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.c:18:13:18:16 | call to rand | Uncontrolled value |
7474
| test.c:35:5:35:5 | r | test.c:34:13:34:18 | call to rand | test.c:35:5:35:5 | r | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.c:34:13:34:18 | call to rand | Uncontrolled value |
@@ -79,13 +79,13 @@ nodes
7979
| test.c:83:9:83:9 | r | test.c:81:23:81:26 | call to rand | test.c:83:9:83:9 | r | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.c:81:23:81:26 | call to rand | Uncontrolled value |
8080
| test.c:100:5:100:5 | r | test.c:99:14:99:19 | call to rand | test.c:100:5:100:5 | r | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.c:99:14:99:19 | call to rand | Uncontrolled value |
8181
| test.c:127:9:127:9 | r | test.c:125:13:125:16 | call to rand | test.c:127:9:127:9 | r | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.c:125:13:125:16 | call to rand | Uncontrolled value |
82-
| test.c:150:9:150:9 | r | test.c:148:22:148:25 | call to rand | test.c:150:9:150:9 | r | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test.c:148:22:148:25 | call to rand | Uncontrolled value |
83-
| test.c:150:9:150:9 | r | test.c:148:22:148:27 | (unsigned int)... | test.c:150:9:150:9 | r | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test.c:148:22:148:25 | call to rand | Uncontrolled value |
82+
| test.c:157:9:157:9 | r | test.c:155:22:155:25 | call to rand | test.c:157:9:157:9 | r | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test.c:155:22:155:25 | call to rand | Uncontrolled value |
83+
| test.c:157:9:157:9 | r | test.c:155:22:155:27 | (unsigned int)... | test.c:157:9:157:9 | r | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test.c:155:22:155:25 | call to rand | Uncontrolled value |
8484
| test.cpp:25:7:25:7 | r | test.cpp:8:9:8:12 | call to rand | test.cpp:25:7:25:7 | r | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:8:9:8:12 | call to rand | Uncontrolled value |
8585
| test.cpp:31:7:31:7 | r | test.cpp:13:10:13:13 | call to rand | test.cpp:31:7:31:7 | r | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:13:10:13:13 | call to rand | Uncontrolled value |
8686
| test.cpp:37:7:37:7 | r | test.cpp:18:9:18:12 | call to rand | test.cpp:37:7:37:7 | r | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:18:9:18:12 | call to rand | Uncontrolled value |
87-
| test.cpp:82:10:82:10 | x | test.cpp:78:10:78:13 | call to rand | test.cpp:82:10:82:10 | x | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:78:10:78:13 | call to rand | Uncontrolled value |
88-
| test.cpp:94:10:94:10 | x | test.cpp:90:10:90:13 | call to rand | test.cpp:94:10:94:10 | x | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:90:10:90:13 | call to rand | Uncontrolled value |
89-
| test.cpp:132:10:132:10 | b | test.cpp:129:10:129:13 | call to rand | test.cpp:132:10:132:10 | b | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:129:10:129:13 | call to rand | Uncontrolled value |
90-
| test.cpp:149:11:149:16 | (int)... | test.cpp:147:11:147:14 | call to rand | test.cpp:149:11:149:16 | (int)... | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:147:11:147:14 | call to rand | Uncontrolled value |
91-
| test.cpp:149:16:149:16 | y | test.cpp:147:11:147:14 | call to rand | test.cpp:149:16:149:16 | y | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:147:11:147:14 | call to rand | Uncontrolled value |
87+
| test.cpp:90:10:90:10 | x | test.cpp:86:10:86:13 | call to rand | test.cpp:90:10:90:10 | x | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:86:10:86:13 | call to rand | Uncontrolled value |
88+
| test.cpp:102:10:102:10 | x | test.cpp:98:10:98:13 | call to rand | test.cpp:102:10:102:10 | x | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:98:10:98:13 | call to rand | Uncontrolled value |
89+
| test.cpp:154:10:154:10 | b | test.cpp:151:10:151:13 | call to rand | test.cpp:154:10:154:10 | b | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:151:10:151:13 | call to rand | Uncontrolled value |
90+
| test.cpp:171:11:171:16 | (int)... | test.cpp:169:11:169:14 | call to rand | test.cpp:171:11:171:16 | (int)... | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:169:11:169:14 | call to rand | Uncontrolled value |
91+
| test.cpp:171:16:171:16 | y | test.cpp:169:11:169:14 | call to rand | test.cpp:171:16:171:16 | y | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.cpp:169:11:169:14 | call to rand | Uncontrolled value |

cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/ArithmeticUncontrolled/test.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,19 @@ void moreTests() {
126126

127127
r = r * 100; // BAD
128128
}
129+
129130
{
130131
int r = rand();
131132

132133
r *= 100; // BAD [NOT DETECTED]
133134
}
134135

136+
137+
138+
139+
140+
141+
135142
{
136143
int r = rand();
137144

cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/ArithmeticUncontrolled/test.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ int rand(int min, int max);
4242
unsigned rand(int max);
4343

4444
void test_with_bounded_randomness() {
45-
int r = rand(0, 10);
46-
r++; // GOOD
45+
int r = rand(0, 10);
46+
r++; // GOOD
4747

4848
unsigned unsigned_r = rand(10);
4949
unsigned_r++; // GOOD
@@ -57,6 +57,14 @@ int test_remainder_subtract()
5757
return x - y; // GOOD (as y <= x)
5858
}
5959

60+
61+
62+
63+
64+
65+
66+
67+
6068
typedef unsigned long size_t;
6169
int snprintf(char *s, size_t n, const char *format, ...);
6270

@@ -124,6 +132,20 @@ int test_conditional_assignment_2()
124132
return y * 10; // GOOD (as y <= 100)
125133
}
126134

135+
136+
137+
138+
139+
140+
141+
142+
143+
144+
145+
146+
147+
148+
127149
int test_underflow()
128150
{
129151
int x = rand();

0 commit comments

Comments
 (0)