Skip to content

Commit

Permalink
Merge pull request #18309 from github/calumgrant/bmn/return-stack-all…
Browse files Browse the repository at this point in the history
…ocated-memory

C++: Fix FPs to cpp/return-stack-allocated-memory
  • Loading branch information
calumgrant authored Dec 20, 2024
2 parents dd021fd + 3193fe8 commit d5571c5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class ReturnStackAllocatedMemoryConfig extends MustFlowConfiguration {
or
node2.(PointerOffsetInstruction).getLeftOperand() = node1
}

override predicate isBarrier(Instruction n) { n.getResultType() instanceof ErroneousType }
}

from
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* 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.
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,5 @@ char* test_strdupa(const char* s) {
void* test_strndupa(const char* s, size_t size) {
char* s2 = strndupa(s, size);
return s2; // BAD
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// semmle-extractor-options: --expect_errors

UNKNOWN_TYPE test_error_value() {
UNKNOWN_TYPE x;
return x; // GOOD: Error return type
}

void* test_error_pointer() {
UNKNOWN_TYPE x;
return &x; // BAD [FALSE NEGATIVE]
}

int* test_error_pointer_member() {
UNKNOWN_TYPE x;
return &x.y; // BAD [FALSE NEGATIVE]
}

0 comments on commit d5571c5

Please sign in to comment.