From 6a7b2e4aa4cae46a6342fe5510530f4aa0ab0550 Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Mon, 16 Oct 2023 10:47:45 +0100 Subject: [PATCH] C++: Add failing test. --- cpp/ql/test/query-tests/Security/CWE/CWE-193/test.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cpp/ql/test/query-tests/Security/CWE/CWE-193/test.cpp b/cpp/ql/test/query-tests/Security/CWE/CWE-193/test.cpp index 58b3e843424..f6983191110 100644 --- a/cpp/ql/test/query-tests/Security/CWE/CWE-193/test.cpp +++ b/cpp/ql/test/query-tests/Security/CWE/CWE-193/test.cpp @@ -848,4 +848,15 @@ void test16_with_malloc(size_t index) { int* newname = (int*)malloc(size); newname[index] = 0; // $ SPURIOUS: alloc=L848 deref=L849 // GOOD [FALSE POSITIVE] } +} + +# define MyMalloc(size) malloc(((size) == 0 ? 1 : (size))) + +void test_regression(size_t size) { + int* p = (int*)MyMalloc(size + 1); + int* chend = p + (size + 1); + + if(p <= chend) { + *p = 42; // BAD [NOT DETECTED] + } } \ No newline at end of file