Skip to content

Commit c1d41b3

Browse files
committed
C++: Add false positive result from pointer-difference expressions.
1 parent 5031b73 commit c1d41b3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ edges
8787
| test.cpp:295:18:295:21 | Chi | test.cpp:298:10:298:27 | ... * ... |
8888
| test.cpp:295:18:295:21 | Chi | test.cpp:298:10:298:27 | ... * ... |
8989
| test.cpp:295:18:295:21 | get_size output argument [array content] | test.cpp:295:18:295:21 | Chi |
90+
| test.cpp:321:15:321:20 | call to getenv | test.cpp:324:9:324:14 | (size_t)... |
91+
| test.cpp:321:15:321:20 | call to getenv | test.cpp:324:9:324:14 | (size_t)... |
92+
| test.cpp:321:15:321:20 | call to getenv | test.cpp:324:9:324:14 | offset |
93+
| test.cpp:321:15:321:20 | call to getenv | test.cpp:324:9:324:14 | offset |
94+
| test.cpp:321:15:321:20 | call to getenv | test.cpp:324:9:324:14 | offset |
95+
| test.cpp:321:15:321:20 | call to getenv | test.cpp:324:9:324:14 | offset |
9096
nodes
9197
| test.cpp:39:21:39:24 | argv | semmle.label | argv |
9298
| test.cpp:39:21:39:24 | argv | semmle.label | argv |
@@ -179,6 +185,13 @@ nodes
179185
| test.cpp:298:10:298:27 | ... * ... | semmle.label | ... * ... |
180186
| test.cpp:298:10:298:27 | ... * ... | semmle.label | ... * ... |
181187
| test.cpp:298:10:298:27 | ... * ... | semmle.label | ... * ... |
188+
| test.cpp:321:15:321:20 | call to getenv | semmle.label | call to getenv |
189+
| test.cpp:321:15:321:20 | call to getenv | semmle.label | call to getenv |
190+
| test.cpp:324:9:324:14 | (size_t)... | semmle.label | (size_t)... |
191+
| test.cpp:324:9:324:14 | (size_t)... | semmle.label | (size_t)... |
192+
| test.cpp:324:9:324:14 | offset | semmle.label | offset |
193+
| test.cpp:324:9:324:14 | offset | semmle.label | offset |
194+
| test.cpp:324:9:324:14 | offset | semmle.label | offset |
182195
#select
183196
| test.cpp:42:31:42:36 | call to malloc | test.cpp:39:21:39:24 | argv | test.cpp:42:38:42:44 | tainted | This allocation size is derived from $@ and might overflow | test.cpp:39:21:39:24 | argv | user input (argv) |
184197
| test.cpp:43:31:43:36 | call to malloc | test.cpp:39:21:39:24 | argv | test.cpp:43:38:43:63 | ... * ... | This allocation size is derived from $@ and might overflow | test.cpp:39:21:39:24 | argv | user input (argv) |
@@ -196,3 +209,4 @@ nodes
196209
| test.cpp:253:4:253:9 | call to malloc | test.cpp:249:20:249:25 | call to getenv | test.cpp:253:11:253:29 | ... * ... | This allocation size is derived from $@ and might overflow | test.cpp:249:20:249:25 | call to getenv | user input (getenv) |
197210
| test.cpp:281:4:281:9 | call to malloc | test.cpp:241:18:241:23 | call to getenv | test.cpp:281:11:281:28 | ... * ... | This allocation size is derived from $@ and might overflow | test.cpp:241:18:241:23 | call to getenv | user input (getenv) |
198211
| test.cpp:298:3:298:8 | call to malloc | test.cpp:241:18:241:23 | call to getenv | test.cpp:298:10:298:27 | ... * ... | This allocation size is derived from $@ and might overflow | test.cpp:241:18:241:23 | call to getenv | user input (getenv) |
212+
| test.cpp:324:2:324:7 | call to malloc | test.cpp:321:15:321:20 | call to getenv | test.cpp:324:9:324:14 | offset | This allocation size is derived from $@ and might overflow | test.cpp:321:15:321:20 | call to getenv | user input (getenv) |

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,12 @@ void equality_cases() {
314314
malloc(size * sizeof(int)); // GOOD
315315
}
316316
}
317+
318+
char * strstr(char *, const char *);
319+
320+
void ptr_diff_case() {
321+
char* user = getenv("USER");
322+
char* admin_begin_pos = strstr(user, "ADMIN");
323+
int offset = admin_begin_pos ? user - admin_begin_pos : 0;
324+
malloc(offset); // GOOD [FALSE POSITIVE]
325+
}

0 commit comments

Comments
 (0)