Skip to content

Commit d450aa2

Browse files
committed
C++: Add some testcases that require path sensitivity.
1 parent 348fab8 commit d450aa2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-416/semmle/tests/UseAfterFree.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
| test.cpp:170:6:170:9 | data | Memory pointed to by 'data' may have been previously freed $@ | test.cpp:165:2:165:5 | call to free | here |
88
| test.cpp:193:6:193:9 | data | Memory pointed to by 'data' may have been previously freed $@ | test.cpp:191:3:191:6 | call to free | here |
99
| test.cpp:201:6:201:6 | x | Memory pointed to by 'x' may have been previously freed $@ | test.cpp:200:2:200:9 | delete | here |
10+
| test.cpp:222:9:222:12 | data | Memory pointed to by 'data' may have been previously freed $@ | test.cpp:223:5:223:8 | call to free | here |
11+
| test.cpp:223:10:223:13 | data | Memory pointed to by 'data' may have been previously freed $@ | test.cpp:223:5:223:8 | call to free | here |
12+
| test.cpp:234:9:234:12 | data | Memory pointed to by 'data' may have been previously freed $@ | test.cpp:230:5:230:8 | call to free | here |

cpp/ql/test/query-tests/Security/CWE/CWE-416/semmle/tests/test.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,24 @@ void regression_test_for_static_var_handling()
213213
data = (char *)malloc(100*sizeof(char));
214214
use(data); // GOOD
215215
}
216+
217+
void test16(int n, bool b) {
218+
char* data = NULL;
219+
for(int i = 0; i < n; ++i) {
220+
if(b) data = (char*)malloc(10 * sizeof(char));
221+
if(!b || data == NULL) return;
222+
use(data); // GOOD [FALSE POSITIVE]
223+
free(data); // GOOD [FALSE POSITIVE]
224+
}
225+
}
226+
227+
void test17(int n, bool b) {
228+
char* data = (char*)malloc(10);
229+
if(b) {
230+
free(data);
231+
}
232+
233+
if(!b) {
234+
use(data); // GOOD [FALSE POSITIVE]
235+
}
236+
}

0 commit comments

Comments
 (0)