Skip to content

Commit 46baf9d

Browse files
committed
C++: Add test cases for an experimental query as well.
1 parent c160e0b commit 46baf9d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-190/AllocMultiplicationOverflow/AllocMultiplicationOverflow.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
edges
22
| test.cpp:22:17:22:21 | ... * ... | test.cpp:23:33:23:37 | size1 |
3+
| test.cpp:37:24:37:27 | size | test.cpp:37:46:37:49 | size |
4+
| test.cpp:45:36:45:40 | ... * ... | test.cpp:37:24:37:27 | size |
35
nodes
46
| test.cpp:13:33:13:37 | ... * ... | semmle.label | ... * ... |
57
| test.cpp:15:31:15:35 | ... * ... | semmle.label | ... * ... |
@@ -8,6 +10,9 @@ nodes
810
| test.cpp:23:33:23:37 | size1 | semmle.label | size1 |
911
| test.cpp:30:27:30:31 | ... * ... | semmle.label | ... * ... |
1012
| test.cpp:31:27:31:31 | ... * ... | semmle.label | ... * ... |
13+
| test.cpp:37:24:37:27 | size | semmle.label | size |
14+
| test.cpp:37:46:37:49 | size | semmle.label | size |
15+
| test.cpp:45:36:45:40 | ... * ... | semmle.label | ... * ... |
1116
subpaths
1217
#select
1318
| 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
1621
| 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 |
1722
| 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 |
1823
| 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 |
24+
| 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 |

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-190/AllocMultiplicationOverflow/test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,18 @@ void test()
3030
char *buffer8 = new char[x * y]; // BAD
3131
char *buffer9 = new char[x * x]; // BAD
3232
}
33+
34+
35+
// --- custom allocators ---
36+
37+
void *MyMalloc1(size_t size) { return malloc(size); } // [additional detection here]
38+
void *MyMalloc2(size_t size);
39+
40+
void customAllocatorTests()
41+
{
42+
int x = getAnInt();
43+
int y = getAnInt();
44+
45+
char *buffer1 = (char *)MyMalloc1(x * y); // BAD [NOT DETECTED]
46+
char *buffer2 = (char *)MyMalloc2(x * y); // BAD [NOT DETECTED]
47+
}

0 commit comments

Comments
 (0)