Skip to content

Commit 366ebca

Browse files
committed
C++: Add cpp/return-stack-allocated-memory test case
1 parent 73194a5 commit 366ebca

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

cpp/ql/test/query-tests/Likely Bugs/Memory Management/ReturnStackAllocatedMemory/ReturnStackAllocatedMemory.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ edges
4848
| test.cpp:249:13:249:20 | call to strndupa | test.cpp:249:13:249:20 | call to strndupa |
4949
| test.cpp:249:13:249:20 | call to strndupa | test.cpp:250:9:250:10 | s2 |
5050
| test.cpp:250:9:250:10 | s2 | test.cpp:250:9:250:10 | (void *)... |
51+
| test.cpp:253:17:253:17 | p | test.cpp:256:10:256:10 | p |
52+
| test.cpp:255:19:255:20 | & ... | test.cpp:253:17:253:17 | p |
53+
| test.cpp:255:20:255:20 | x | test.cpp:255:19:255:20 | & ... |
5154
nodes
5255
| test.cpp:17:9:17:11 | & ... | semmle.label | & ... |
5356
| test.cpp:17:10:17:11 | mc | semmle.label | mc |
@@ -114,6 +117,10 @@ nodes
114117
| test.cpp:249:13:249:20 | call to strndupa | semmle.label | call to strndupa |
115118
| test.cpp:250:9:250:10 | (void *)... | semmle.label | (void *)... |
116119
| test.cpp:250:9:250:10 | s2 | semmle.label | s2 |
120+
| test.cpp:253:17:253:17 | p | semmle.label | p |
121+
| test.cpp:255:19:255:20 | & ... | semmle.label | & ... |
122+
| test.cpp:255:20:255:20 | x | semmle.label | x |
123+
| test.cpp:256:10:256:10 | p | semmle.label | p |
117124
#select
118125
| test.cpp:17:9:17:11 | CopyValue: & ... | test.cpp:17:10:17:11 | mc | test.cpp:17:9:17:11 | & ... | May return stack-allocated memory from $@. | test.cpp:17:10:17:11 | mc | mc |
119126
| test.cpp:25:9:25:11 | Load: ptr | test.cpp:23:18:23:19 | mc | test.cpp:25:9:25:11 | ptr | May return stack-allocated memory from $@. | test.cpp:23:18:23:19 | mc | mc |
@@ -131,3 +138,4 @@ nodes
131138
| test.cpp:238:9:238:9 | Load: p | test.cpp:237:12:237:17 | call to alloca | test.cpp:238:9:238:9 | p | May return stack-allocated memory from $@. | test.cpp:237:12:237:17 | call to alloca | call to alloca |
132139
| test.cpp:245:9:245:15 | Call: call to strdupa | test.cpp:245:9:245:15 | call to strdupa | test.cpp:245:9:245:15 | call to strdupa | May return stack-allocated memory from $@. | test.cpp:245:9:245:15 | call to strdupa | call to strdupa |
133140
| test.cpp:250:9:250:10 | Convert: (void *)... | test.cpp:249:13:249:20 | call to strndupa | test.cpp:250:9:250:10 | (void *)... | May return stack-allocated memory from $@. | test.cpp:249:13:249:20 | call to strndupa | call to strndupa |
141+
| test.cpp:256:10:256:10 | Load: p | test.cpp:255:20:255:20 | x | test.cpp:256:10:256:10 | p | May return stack-allocated memory from $@. | test.cpp:255:20:255:20 | x | x |

cpp/ql/test/query-tests/Likely Bugs/Memory Management/ReturnStackAllocatedMemory/test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,8 @@ void* test_strndupa(const char* s, size_t size) {
250250
return s2; // BAD
251251
}
252252

253+
int* f_rec(int *p, bool b) {
254+
int x;
255+
int* px = f_rec(&x, b); // GOOD [FALSE POSITIVE]
256+
return p;
257+
}

0 commit comments

Comments
 (0)