Skip to content

Commit 13823df

Browse files
committed
C++: Remove underflow detection.
1 parent 9e04112 commit 13823df

File tree

4 files changed

+4
-30
lines changed

4 files changed

+4
-30
lines changed

cpp/ql/src/Security/CWE/CWE-190/ArithmeticUncontrolled.ql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ private class RandS extends RandomFunction {
7474

7575
predicate missingGuard(VariableAccess va, string effect) {
7676
exists(Operation op | op.getAnOperand() = va |
77-
missingGuardAgainstUnderflow(op, va) and
78-
effect = "underflow" and
79-
not op instanceof MulExpr // random numbers are usually non-negative, so multiplication doesn't underflow.
80-
or
8177
missingGuardAgainstOverflow(op, va) and effect = "overflow"
8278
)
8379
}

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ edges
22
| test.c:18:13:18:16 | call to rand | test.c:21:17:21:17 | r |
33
| test.c:34:13:34:18 | call to rand | test.c:35:5:35:5 | r |
44
| test.c:44:13:44:16 | call to rand | test.c:45:5:45:5 | r |
5-
| test.c:75:13:75:19 | call to rand | test.c:77:9:77:9 | r |
6-
| test.c:75:13:75:19 | call to rand | test.c:77:9:77:9 | r |
7-
| test.c:81:14:81:17 | call to rand | test.c:83:9:83:9 | r |
8-
| test.c:81:23:81:26 | call to rand | test.c:83:9:83:9 | r |
9-
| test.c:99:14:99:19 | call to rand | test.c:100:5:100:5 | r |
105
| test.c:125:13:125:16 | call to rand | test.c:127:9:127:9 | r |
116
| test.cpp:8:9:8:12 | Store | test.cpp:24:11:24:18 | call to get_rand |
127
| test.cpp:8:9:8:12 | call to rand | test.cpp:8:9:8:12 | Store |
@@ -19,7 +14,6 @@ edges
1914
| test.cpp:30:13:30:14 | get_rand2 output argument [[]] | test.cpp:30:13:30:14 | Chi |
2015
| test.cpp:36:13:36:13 | Chi | test.cpp:37:7:37:7 | r |
2116
| test.cpp:36:13:36:13 | get_rand3 output argument [[]] | test.cpp:36:13:36:13 | Chi |
22-
| test.cpp:54:10:54:13 | call to rand | test.cpp:57:9:57:9 | x |
2317
| test.cpp:78:10:78:13 | call to rand | test.cpp:82:10:82:10 | x |
2418
| test.cpp:90:10:90:13 | call to rand | test.cpp:94:10:94:10 | x |
2519
| test.cpp:129:10:129:13 | call to rand | test.cpp:132:10:132:10 | b |
@@ -32,14 +26,6 @@ nodes
3226
| test.c:35:5:35:5 | r | semmle.label | r |
3327
| test.c:44:13:44:16 | call to rand | semmle.label | call to rand |
3428
| test.c:45:5:45:5 | r | semmle.label | r |
35-
| test.c:75:13:75:19 | call to rand | semmle.label | call to rand |
36-
| test.c:75:13:75:19 | call to rand | semmle.label | call to rand |
37-
| test.c:77:9:77:9 | r | semmle.label | r |
38-
| test.c:81:14:81:17 | call to rand | semmle.label | call to rand |
39-
| test.c:81:23:81:26 | call to rand | semmle.label | call to rand |
40-
| test.c:83:9:83:9 | r | semmle.label | r |
41-
| test.c:99:14:99:19 | call to rand | semmle.label | call to rand |
42-
| test.c:100:5:100:5 | r | semmle.label | r |
4329
| test.c:125:13:125:16 | call to rand | semmle.label | call to rand |
4430
| test.c:127:9:127:9 | r | semmle.label | r |
4531
| test.cpp:8:9:8:12 | Store | semmle.label | Store |
@@ -56,8 +42,6 @@ nodes
5642
| test.cpp:36:13:36:13 | Chi | semmle.label | Chi |
5743
| test.cpp:36:13:36:13 | get_rand3 output argument [[]] | semmle.label | get_rand3 output argument [[]] |
5844
| test.cpp:37:7:37:7 | r | semmle.label | r |
59-
| test.cpp:54:10:54:13 | call to rand | semmle.label | call to rand |
60-
| test.cpp:57:9:57:9 | x | semmle.label | x |
6145
| test.cpp:78:10:78:13 | call to rand | semmle.label | call to rand |
6246
| test.cpp:82:10:82:10 | x | semmle.label | x |
6347
| test.cpp:90:10:90:13 | call to rand | semmle.label | call to rand |
@@ -71,16 +55,10 @@ nodes
7155
| 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 |
7256
| 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 |
7357
| test.c:45:5:45:5 | r | test.c:44:13:44:16 | call to rand | test.c:45:5:45:5 | r | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.c:44:13:44:16 | call to rand | Uncontrolled value |
74-
| test.c:77:9:77:9 | r | test.c:75:13:75:19 | call to rand | test.c:77:9:77:9 | r | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test.c:75:13:75:19 | call to rand | Uncontrolled value |
75-
| test.c:77:9:77:9 | r | test.c:75:13:75:19 | call to rand | test.c:77:9:77:9 | r | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test.c:75:13:75:19 | call to rand | Uncontrolled value |
76-
| test.c:83:9:83:9 | r | test.c:81:14:81:17 | call to rand | test.c:83:9:83:9 | r | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test.c:81:14:81:17 | call to rand | Uncontrolled value |
77-
| 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 underflow. | test.c:81:23:81:26 | call to rand | Uncontrolled value |
78-
| 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 underflow. | test.c:99:14:99:19 | call to rand | Uncontrolled value |
7958
| 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 |
8059
| 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 |
8160
| 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 |
8261
| 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 |
83-
| test.cpp:57:9:57:9 | x | test.cpp:54:10:54:13 | call to rand | test.cpp:57:9:57:9 | x | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test.cpp:54:10:54:13 | call to rand | Uncontrolled value |
8462
| 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 |
8563
| 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 |
8664
| 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 |

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ void randomTester() {
7474
{
7575
int r = RAND2();
7676

77-
r = r - 100; // BAD
77+
r = r - 100; // GOOD
7878
}
7979

8080
{
8181
int r = (rand() ^ rand());
8282

83-
r = r - 100; // BAD
83+
r = r - 100; // GOOD
8484
}
8585

8686
{
@@ -97,7 +97,7 @@ void randomTester() {
9797
int r = 0;
9898
int *ptr_r = &r;
9999
*ptr_r = RAND();
100-
r -= 100; // BAD
100+
r -= 100; // GOOD
101101
}
102102

103103
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int test_remainder_subtract()
5454
int x = rand();
5555
int y = x % 100; // y <= x
5656

57-
return x - y; // GOOD (as y <= x) [FALSE POSITIVE]
57+
return x - y; // GOOD (as y <= x)
5858
}
5959

6060
typedef unsigned long size_t;

0 commit comments

Comments
 (0)