Skip to content

Commit 617bdbc

Browse files
committed
C++: test for guard-by-return in Overflow.qll
1 parent d5682f1 commit 617bdbc

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ edges
1111
| test.c:137:13:137:16 | call to rand | test.c:139:10:139:10 | r |
1212
| test.c:155:22:155:25 | call to rand | test.c:157:9:157:9 | r |
1313
| test.c:155:22:155:27 | (unsigned int)... | test.c:157:9:157:9 | r |
14+
| test.c:162:19:162:38 | (unsigned int)... | test.c:166:16:166:19 | data |
15+
| test.c:162:33:162:36 | call to rand | test.c:166:16:166:19 | data |
1416
| test.cpp:6:5:6:12 | ReturnValue | test.cpp:24:11:24:18 | call to get_rand |
1517
| test.cpp:8:9:8:12 | call to rand | test.cpp:6:5:6:12 | ReturnValue |
1618
| test.cpp:13:2:13:6 | * ... [post update] | test.cpp:30:13:30:14 | & ... [post update] |
@@ -57,6 +59,9 @@ nodes
5759
| test.c:155:22:155:25 | call to rand | semmle.label | call to rand |
5860
| test.c:155:22:155:27 | (unsigned int)... | semmle.label | (unsigned int)... |
5961
| test.c:157:9:157:9 | r | semmle.label | r |
62+
| test.c:162:19:162:38 | (unsigned int)... | semmle.label | (unsigned int)... |
63+
| test.c:162:33:162:36 | call to rand | semmle.label | call to rand |
64+
| test.c:166:16:166:19 | data | semmle.label | data |
6065
| test.cpp:6:5:6:12 | ReturnValue | semmle.label | ReturnValue |
6166
| test.cpp:8:9:8:12 | call to rand | semmle.label | call to rand |
6267
| test.cpp:13:2:13:6 | * ... [post update] | semmle.label | * ... [post update] |
@@ -104,6 +109,8 @@ subpaths
104109
| test.c:139:10:139:10 | r | test.c:137:13:137:16 | call to rand | test.c:139:10:139:10 | r | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.c:137:13:137:16 | call to rand | Uncontrolled value |
105110
| 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 |
106111
| 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 |
112+
| test.c:166:16:166:19 | data | test.c:162:19:162:38 | (unsigned int)... | test.c:166:16:166:19 | data | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test.c:162:33:162:36 | call to rand | Uncontrolled value |
113+
| test.c:166:16:166:19 | data | test.c:162:33:162:36 | call to rand | test.c:166:16:166:19 | data | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test.c:162:33:162:36 | call to rand | Uncontrolled value |
107114
| 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 |
108115
| 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 |
109116
| 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 |

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,11 @@ void moreTests() {
157157
r = r - 100; // BAD
158158
}
159159
}
160+
161+
void guarded_test(unsigned p) {
162+
unsigned data = (unsigned int)rand();
163+
if (p >= data) {
164+
return;
165+
}
166+
unsigned z = data - p; // GOOD [FALSE POSITIVE]
167+
}

0 commit comments

Comments
 (0)