From 725122decc6271e53188237b77103acd47928c45 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Fri, 26 Mar 2021 17:25:55 +0000 Subject: [PATCH 1/4] C++: Replace toString logic. --- .../WrongInDetectingAndHandlingMemoryAllocationErrors.ql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/ql/src/experimental/Security/CWE/CWE-570/WrongInDetectingAndHandlingMemoryAllocationErrors.ql b/cpp/ql/src/experimental/Security/CWE/CWE-570/WrongInDetectingAndHandlingMemoryAllocationErrors.ql index dd9c16fac114..ea946c47c761 100644 --- a/cpp/ql/src/experimental/Security/CWE/CWE-570/WrongInDetectingAndHandlingMemoryAllocationErrors.ql +++ b/cpp/ql/src/experimental/Security/CWE/CWE-570/WrongInDetectingAndHandlingMemoryAllocationErrors.ql @@ -74,7 +74,7 @@ class WrongCheckErrorOperatorNew extends FunctionCall { /** * Holds if `(std::nothrow)` exists in call `operator new`. */ - predicate isExistsNothrow() { this.getAChild().toString() = "nothrow" } + predicate isExistsNothrow() { getTarget().isNoExcept() or getTarget().isNoThrow() } } from WrongCheckErrorOperatorNew op From 4100d68a71c8600b74360d4489cc41815ab3c4ae Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Fri, 26 Mar 2021 18:14:31 +0000 Subject: [PATCH 2/4] C++: Test failures. --- ...ongInDetectingAndHandlingMemoryAllocationErrors.expected | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/WrongInDetectingAndHandlingMemoryAllocationErrors.expected b/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/WrongInDetectingAndHandlingMemoryAllocationErrors.expected index 80e82cff2129..d94564d7729f 100644 --- a/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/WrongInDetectingAndHandlingMemoryAllocationErrors.expected +++ b/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/WrongInDetectingAndHandlingMemoryAllocationErrors.expected @@ -1,5 +1,5 @@ | test.cpp:30:15:30:26 | call to operator new[] | memory allocation error check is incorrect or missing | | test.cpp:38:9:38:20 | call to operator new[] | memory allocation error check is incorrect or missing | -| test.cpp:50:13:50:38 | call to operator new[] | memory allocation error check is incorrect or missing | -| test.cpp:51:22:51:47 | call to operator new[] | memory allocation error check is incorrect or missing | -| test.cpp:53:18:53:43 | call to operator new[] | memory allocation error check is incorrect or missing | +| test.cpp:81:18:81:43 | call to operator new[] | memory allocation error check is incorrect or missing | +| test.cpp:87:14:87:39 | call to operator new[] | memory allocation error check is incorrect or missing | +| test.cpp:92:13:92:38 | call to operator new[] | memory allocation error check is incorrect or missing | From c6e7b8d4fd04f2c96592c4f112f93a6e55a2ed46 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Fri, 26 Mar 2021 19:12:09 +0000 Subject: [PATCH 3/4] C++: Repair test. --- ...ongInDetectingAndHandlingMemoryAllocationErrors.expected | 6 +++--- .../query-tests/Security/CWE/CWE-570/semmle/tests/test.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/WrongInDetectingAndHandlingMemoryAllocationErrors.expected b/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/WrongInDetectingAndHandlingMemoryAllocationErrors.expected index d94564d7729f..80e82cff2129 100644 --- a/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/WrongInDetectingAndHandlingMemoryAllocationErrors.expected +++ b/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/WrongInDetectingAndHandlingMemoryAllocationErrors.expected @@ -1,5 +1,5 @@ | test.cpp:30:15:30:26 | call to operator new[] | memory allocation error check is incorrect or missing | | test.cpp:38:9:38:20 | call to operator new[] | memory allocation error check is incorrect or missing | -| test.cpp:81:18:81:43 | call to operator new[] | memory allocation error check is incorrect or missing | -| test.cpp:87:14:87:39 | call to operator new[] | memory allocation error check is incorrect or missing | -| test.cpp:92:13:92:38 | call to operator new[] | memory allocation error check is incorrect or missing | +| test.cpp:50:13:50:38 | call to operator new[] | memory allocation error check is incorrect or missing | +| test.cpp:51:22:51:47 | call to operator new[] | memory allocation error check is incorrect or missing | +| test.cpp:53:18:53:43 | call to operator new[] | memory allocation error check is incorrect or missing | diff --git a/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/test.cpp b/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/test.cpp index e4aa8cf29766..4fc12d9ccbfe 100644 --- a/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/test.cpp +++ b/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/test.cpp @@ -14,8 +14,8 @@ using namespace std; void* operator new(std::size_t _Size); void* operator new[](std::size_t _Size); -void* operator new( std::size_t count, const std::nothrow_t& tag ); -void* operator new[]( std::size_t count, const std::nothrow_t& tag ); +void* operator new( std::size_t count, const std::nothrow_t& tag ) noexcept; +void* operator new[]( std::size_t count, const std::nothrow_t& tag ) noexcept; void badNew_0_0() { From 85ecfe2723c236fb7c4fcb529cea9b7c99c3dac0 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 31 Mar 2021 11:34:56 +0100 Subject: [PATCH 4/4] Update cpp/ql/src/experimental/Security/CWE/CWE-570/WrongInDetectingAndHandlingMemoryAllocationErrors.ql Co-authored-by: Mathias Vorreiter Pedersen --- .../WrongInDetectingAndHandlingMemoryAllocationErrors.ql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/ql/src/experimental/Security/CWE/CWE-570/WrongInDetectingAndHandlingMemoryAllocationErrors.ql b/cpp/ql/src/experimental/Security/CWE/CWE-570/WrongInDetectingAndHandlingMemoryAllocationErrors.ql index ea946c47c761..4869da7e6f30 100644 --- a/cpp/ql/src/experimental/Security/CWE/CWE-570/WrongInDetectingAndHandlingMemoryAllocationErrors.ql +++ b/cpp/ql/src/experimental/Security/CWE/CWE-570/WrongInDetectingAndHandlingMemoryAllocationErrors.ql @@ -72,7 +72,7 @@ class WrongCheckErrorOperatorNew extends FunctionCall { } /** - * Holds if `(std::nothrow)` exists in call `operator new`. + * Holds if `(std::nothrow)` or `(std::noexcept)` exists in call `operator new`. */ predicate isExistsNothrow() { getTarget().isNoExcept() or getTarget().isNoThrow() } }