Skip to content

Commit 7c8c209

Browse files
committed
C++: Add real-world false positive from the 'cpp/return-stack-allocated-memory' query.
1 parent 117795c commit 7c8c209

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ edges
100100
| test.cpp:190:10:190:13 | Unary | test.cpp:190:10:190:13 | (reference dereference) |
101101
| test.cpp:190:10:190:13 | Unary | test.cpp:190:10:190:13 | (reference to) |
102102
| test.cpp:190:10:190:13 | pRef | test.cpp:190:10:190:13 | Unary |
103+
| test.cpp:222:9:222:17 | (void *)... | test.cpp:222:9:222:17 | StoreValue |
104+
| test.cpp:222:16:222:17 | & ... | test.cpp:222:16:222:17 | Unary |
105+
| test.cpp:222:16:222:17 | Unary | test.cpp:222:9:222:17 | (void *)... |
106+
| test.cpp:222:17:222:17 | Unary | test.cpp:222:16:222:17 | & ... |
107+
| test.cpp:222:17:222:17 | p | test.cpp:222:17:222:17 | Unary |
103108
nodes
104109
| test.cpp:17:9:17:11 | & ... | semmle.label | & ... |
105110
| test.cpp:17:9:17:11 | StoreValue | semmle.label | StoreValue |
@@ -215,6 +220,12 @@ nodes
215220
| test.cpp:190:10:190:13 | Unary | semmle.label | Unary |
216221
| test.cpp:190:10:190:13 | Unary | semmle.label | Unary |
217222
| test.cpp:190:10:190:13 | pRef | semmle.label | pRef |
223+
| test.cpp:222:9:222:17 | (void *)... | semmle.label | (void *)... |
224+
| test.cpp:222:9:222:17 | StoreValue | semmle.label | StoreValue |
225+
| test.cpp:222:16:222:17 | & ... | semmle.label | & ... |
226+
| test.cpp:222:16:222:17 | Unary | semmle.label | Unary |
227+
| test.cpp:222:17:222:17 | Unary | semmle.label | Unary |
228+
| test.cpp:222:17:222:17 | p | semmle.label | p |
218229
#select
219230
| test.cpp:17:9:17:11 | StoreValue | test.cpp:17:10:17:11 | mc | test.cpp:17:9:17:11 | StoreValue | May return stack-allocated memory from $@. | test.cpp:17:10:17:11 | mc | mc |
220231
| test.cpp:25:9:25:11 | StoreValue | test.cpp:23:18:23:19 | mc | test.cpp:25:9:25:11 | StoreValue | May return stack-allocated memory from $@. | test.cpp:23:18:23:19 | mc | mc |
@@ -229,3 +240,4 @@ nodes
229240
| test.cpp:177:10:177:23 | StoreValue | test.cpp:176:25:176:34 | localArray | test.cpp:177:10:177:23 | StoreValue | May return stack-allocated memory from $@. | test.cpp:176:25:176:34 | localArray | localArray |
230241
| test.cpp:183:10:183:19 | StoreValue | test.cpp:182:21:182:27 | myLocal | test.cpp:183:10:183:19 | StoreValue | May return stack-allocated memory from $@. | test.cpp:182:21:182:27 | myLocal | myLocal |
231242
| test.cpp:190:10:190:13 | StoreValue | test.cpp:189:16:189:16 | p | test.cpp:190:10:190:13 | StoreValue | May return stack-allocated memory from $@. | test.cpp:189:16:189:16 | p | p |
243+
| test.cpp:222:9:222:17 | StoreValue | test.cpp:222:17:222:17 | p | test.cpp:222:9:222:17 | StoreValue | May return stack-allocated memory from $@. | test.cpp:222:17:222:17 | p | p |

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
@@ -216,3 +216,8 @@ auto make_read_port()
216216
auto ptr = port.get();
217217
return ptr; // GOOD
218218
}
219+
220+
void* get_sp() {
221+
int p;
222+
return (void*)&p; // GOOD: The function name makes it sound like the programmer intended to get the value of the stack pointer. [FALSE POSITIVE]
223+
}

0 commit comments

Comments
 (0)