Skip to content

Commit d5571c5

Browse files
authored
Merge pull request #18309 from github/calumgrant/bmn/return-stack-allocated-memory
C++: Fix FPs to cpp/return-stack-allocated-memory
2 parents dd021fd + 3193fe8 commit d5571c5

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

cpp/ql/src/Likely Bugs/Memory Management/ReturnStackAllocatedMemory.ql

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class ReturnStackAllocatedMemoryConfig extends MustFlowConfiguration {
9292
or
9393
node2.(PointerOffsetInstruction).getLeftOperand() = node1
9494
}
95+
96+
override predicate isBarrier(Instruction n) { n.getResultType() instanceof ErroneousType }
9597
}
9698

9799
from
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The "Returning stack-allocated memory" query (`cpp/return-stack-allocated-memory`) no longer produces results if there is an extraction error in the returned expression.

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,5 @@ char* test_strdupa(const char* s) {
248248
void* test_strndupa(const char* s, size_t size) {
249249
char* s2 = strndupa(s, size);
250250
return s2; // BAD
251-
}
251+
}
252+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// semmle-extractor-options: --expect_errors
2+
3+
UNKNOWN_TYPE test_error_value() {
4+
UNKNOWN_TYPE x;
5+
return x; // GOOD: Error return type
6+
}
7+
8+
void* test_error_pointer() {
9+
UNKNOWN_TYPE x;
10+
return &x; // BAD [FALSE NEGATIVE]
11+
}
12+
13+
int* test_error_pointer_member() {
14+
UNKNOWN_TYPE x;
15+
return &x.y; // BAD [FALSE NEGATIVE]
16+
}

0 commit comments

Comments
 (0)