diff --git a/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-190/AllocMultiplicationOverflow/AllocMultiplicationOverflow.expected b/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-190/AllocMultiplicationOverflow/AllocMultiplicationOverflow.expected index 03a070f3c91..e7ca1a621b5 100644 --- a/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-190/AllocMultiplicationOverflow/AllocMultiplicationOverflow.expected +++ b/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-190/AllocMultiplicationOverflow/AllocMultiplicationOverflow.expected @@ -1,5 +1,7 @@ edges | test.cpp:22:17:22:21 | ... * ... | test.cpp:23:33:23:37 | size1 | +| test.cpp:37:24:37:27 | size | test.cpp:37:46:37:49 | size | +| test.cpp:45:36:45:40 | ... * ... | test.cpp:37:24:37:27 | size | nodes | test.cpp:13:33:13:37 | ... * ... | semmle.label | ... * ... | | test.cpp:15:31:15:35 | ... * ... | semmle.label | ... * ... | @@ -8,6 +10,9 @@ nodes | test.cpp:23:33:23:37 | size1 | semmle.label | size1 | | test.cpp:30:27:30:31 | ... * ... | semmle.label | ... * ... | | test.cpp:31:27:31:31 | ... * ... | semmle.label | ... * ... | +| test.cpp:37:24:37:27 | size | semmle.label | size | +| test.cpp:37:46:37:49 | size | semmle.label | size | +| test.cpp:45:36:45:40 | ... * ... | semmle.label | ... * ... | subpaths #select | test.cpp:13:33:13:37 | ... * ... | test.cpp:13:33:13:37 | ... * ... | test.cpp:13:33:13:37 | ... * ... | Potentially overflowing value from $@ is used in the size of this allocation. | test.cpp:13:33:13:37 | ... * ... | multiplication | @@ -16,3 +21,4 @@ subpaths | test.cpp:23:33:23:37 | size1 | test.cpp:22:17:22:21 | ... * ... | test.cpp:23:33:23:37 | size1 | Potentially overflowing value from $@ is used in the size of this allocation. | test.cpp:22:17:22:21 | ... * ... | multiplication | | test.cpp:30:27:30:31 | ... * ... | test.cpp:30:27:30:31 | ... * ... | test.cpp:30:27:30:31 | ... * ... | Potentially overflowing value from $@ is used in the size of this allocation. | test.cpp:30:27:30:31 | ... * ... | multiplication | | test.cpp:31:27:31:31 | ... * ... | test.cpp:31:27:31:31 | ... * ... | test.cpp:31:27:31:31 | ... * ... | Potentially overflowing value from $@ is used in the size of this allocation. | test.cpp:31:27:31:31 | ... * ... | multiplication | +| test.cpp:37:46:37:49 | size | test.cpp:45:36:45:40 | ... * ... | test.cpp:37:46:37:49 | size | Potentially overflowing value from $@ is used in the size of this allocation. | test.cpp:45:36:45:40 | ... * ... | multiplication | diff --git a/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-190/AllocMultiplicationOverflow/test.cpp b/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-190/AllocMultiplicationOverflow/test.cpp index ab26fef3ed0..9b351d42ae7 100644 --- a/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-190/AllocMultiplicationOverflow/test.cpp +++ b/cpp/ql/test/experimental/query-tests/Security/CWE/CWE-190/AllocMultiplicationOverflow/test.cpp @@ -30,3 +30,18 @@ void test() char *buffer8 = new char[x * y]; // BAD char *buffer9 = new char[x * x]; // BAD } + + +// --- custom allocators --- + +void *MyMalloc1(size_t size) { return malloc(size); } // [additional detection here] +void *MyMalloc2(size_t size); + +void customAllocatorTests() +{ + int x = getAnInt(); + int y = getAnInt(); + + char *buffer1 = (char *)MyMalloc1(x * y); // BAD [NOT DETECTED] + char *buffer2 = (char *)MyMalloc2(x * y); // BAD [NOT DETECTED] +}