Skip to content

Commit 18e5d3c

Browse files
committed
C++: Add false positive with multiplication.
1 parent 64001cc commit 18e5d3c

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ edges
1919
| test.c:99:14:99:19 | call to rand | test.c:100:5:100:5 | r |
2020
| test.c:99:14:99:19 | call to rand | test.c:100:5:100:5 | r |
2121
| test.c:99:14:99:19 | call to rand | test.c:100:5:100:5 | r |
22+
| test.c:104:13:104:16 | call to rand | test.c:106:5:106:11 | r |
23+
| test.c:104:13:104:16 | call to rand | test.c:106:5:106:11 | r |
24+
| test.c:106:5:106:11 | r | test.c:110:18:110:18 | r |
25+
| test.c:110:18:110:18 | r | test.c:111:3:111:3 | r |
26+
| test.c:110:18:110:18 | r | test.c:111:3:111:3 | r |
2227
| test.cpp:8:9:8:12 | Store | test.cpp:24:11:24:18 | call to get_rand |
2328
| test.cpp:8:9:8:12 | call to rand | test.cpp:8:9:8:12 | Store |
2429
| test.cpp:8:9:8:12 | call to rand | test.cpp:8:9:8:12 | Store |
@@ -62,6 +67,13 @@ nodes
6267
| test.c:100:5:100:5 | r | semmle.label | r |
6368
| test.c:100:5:100:5 | r | semmle.label | r |
6469
| test.c:100:5:100:5 | r | semmle.label | r |
70+
| test.c:104:13:104:16 | call to rand | semmle.label | call to rand |
71+
| test.c:104:13:104:16 | call to rand | semmle.label | call to rand |
72+
| test.c:106:5:106:11 | r | semmle.label | r |
73+
| test.c:110:18:110:18 | r | semmle.label | r |
74+
| test.c:111:3:111:3 | r | semmle.label | r |
75+
| test.c:111:3:111:3 | r | semmle.label | r |
76+
| test.c:111:3:111:3 | r | semmle.label | r |
6577
| test.cpp:8:9:8:12 | Store | semmle.label | Store |
6678
| test.cpp:8:9:8:12 | call to rand | semmle.label | call to rand |
6779
| test.cpp:8:9:8:12 | call to rand | semmle.label | call to rand |
@@ -93,6 +105,7 @@ nodes
93105
| 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 |
94106
| test.c:77:9:77:9 | r | test.c:75:13:75:19 | ... ^ ... | 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 | ... ^ ... | Uncontrolled value |
95107
| 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 |
108+
| test.c:111:3:111:3 | r | test.c:104:13:104:16 | call to rand | test.c:111:3:111:3 | r | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.c:104:13:104:16 | call to rand | Uncontrolled value |
96109
| 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 |
97110
| 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 |
98111
| 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/uncontrolled/test.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
int rand(void);
55
void trySlice(int start, int end);
6+
void add_100(int);
67

78
#define RAND() rand()
89
#define RANDN(n) (rand() % n)
910
#define RAND2() (rand() ^ rand())
10-
11-
11+
#define RAND_MAX 32767
1212

1313

1414

@@ -99,4 +99,14 @@ void randomTester() {
9999
*ptr_r = RAND();
100100
r -= 100; // BAD
101101
}
102+
103+
{
104+
int r = rand();
105+
r = ((2.0 / (RAND_MAX + 1)) * r - 1.0);
106+
add_100(r);
107+
}
102108
}
109+
110+
void add_100(int r) {
111+
r += 100; // GOOD [FALSE POSITIVE]
112+
}

0 commit comments

Comments
 (0)