From 14cef6a20722e36ca0cdcdfe008add473183efe8 Mon Sep 17 00:00:00 2001 From: Calum Grant Date: Tue, 17 Dec 2024 15:58:39 +0000 Subject: [PATCH] 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 +}