From 14cef6a20722e36ca0cdcdfe008add473183efe8 Mon Sep 17 00:00:00 2001 From: Calum Grant Date: Tue, 17 Dec 2024 15:58:39 +0000 Subject: [PATCH 1/2] C++: Fix FPs to cpp/return-stack-allocated-memory --- .../Memory Management/ReturnStackAllocatedMemory.ql | 2 ++ .../ReturnStackAllocatedMemory/test.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cpp/ql/src/Likely Bugs/Memory Management/ReturnStackAllocatedMemory.ql b/cpp/ql/src/Likely Bugs/Memory Management/ReturnStackAllocatedMemory.ql index 02678beaf124..b87889103322 100644 --- a/cpp/ql/src/Likely Bugs/Memory Management/ReturnStackAllocatedMemory.ql +++ b/cpp/ql/src/Likely Bugs/Memory Management/ReturnStackAllocatedMemory.ql @@ -92,6 +92,8 @@ class ReturnStackAllocatedMemoryConfig extends MustFlowConfiguration { or node2.(PointerOffsetInstruction).getLeftOperand() = node1 } + + override predicate isBarrier(Instruction n) { n.getResultType() instanceof ErroneousType } } from diff --git a/cpp/ql/test/query-tests/Likely Bugs/Memory Management/ReturnStackAllocatedMemory/test.cpp b/cpp/ql/test/query-tests/Likely Bugs/Memory Management/ReturnStackAllocatedMemory/test.cpp index 44afcd7ee5f8..e8f772968940 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Memory Management/ReturnStackAllocatedMemory/test.cpp +++ b/cpp/ql/test/query-tests/Likely Bugs/Memory Management/ReturnStackAllocatedMemory/test.cpp @@ -1,4 +1,4 @@ -// semmle-extractor-options: -std=c++14 +// semmle-extractor-options: -std=c++14 --expect_errors class MyClass { public: @@ -248,4 +248,9 @@ char* test_strdupa(const char* s) { void* test_strndupa(const char* s, size_t size) { char* s2 = strndupa(s, size); return s2; // BAD -} \ No newline at end of file +} + +UNKNOWN_TYPE test_error_type() { + UNKNOWN_TYPE x; + return x; // GOOD: Don't report error types +} From fabacebd4b3bf935ec2023f5bc7b9db92dd2ae91 Mon Sep 17 00:00:00 2001 From: Calum Grant Date: Wed, 18 Dec 2024 14:37:43 +0000 Subject: [PATCH 2/2] C++: Change note --- .../change-notes/2024-12-18-return-stack-allocated-memory.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 cpp/ql/src/change-notes/2024-12-18-return-stack-allocated-memory.md diff --git a/cpp/ql/src/change-notes/2024-12-18-return-stack-allocated-memory.md b/cpp/ql/src/change-notes/2024-12-18-return-stack-allocated-memory.md new file mode 100644 index 000000000000..d9db04ae7259 --- /dev/null +++ b/cpp/ql/src/change-notes/2024-12-18-return-stack-allocated-memory.md @@ -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 type of the function.