File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed
cpp/ql/test/experimental/query-tests/Security/CWE/CWE-190/AllocMultiplicationOverflow Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ edges
2+ | test.cpp:22:17:22:21 | ... * ... | test.cpp:23:33:23:37 | size1 |
3+ nodes
4+ | test.cpp:13:33:13:37 | ... * ... | semmle.label | ... * ... |
5+ | test.cpp:15:31:15:35 | ... * ... | semmle.label | ... * ... |
6+ | test.cpp:19:34:19:38 | ... * ... | semmle.label | ... * ... |
7+ | test.cpp:22:17:22:21 | ... * ... | semmle.label | ... * ... |
8+ | test.cpp:23:33:23:37 | size1 | semmle.label | size1 |
9+ | test.cpp:30:27:30:31 | ... * ... | semmle.label | ... * ... |
10+ | test.cpp:31:27:31:31 | ... * ... | semmle.label | ... * ... |
11+ #select
12+ | test.cpp:13:33:13:37 | ... * ... | test.cpp:13:33:13:37 | ... * ... | test.cpp:13:33:13:37 | ... * ... | $@ in test | test.cpp:13:33:13:37 | ... * ... | here |
13+ | test.cpp:15:31:15:35 | ... * ... | test.cpp:15:31:15:35 | ... * ... | test.cpp:15:31:15:35 | ... * ... | $@ in test | test.cpp:15:31:15:35 | ... * ... | here |
14+ | test.cpp:19:34:19:38 | ... * ... | test.cpp:19:34:19:38 | ... * ... | test.cpp:19:34:19:38 | ... * ... | $@ in test | test.cpp:19:34:19:38 | ... * ... | here |
15+ | test.cpp:23:33:23:37 | size1 | test.cpp:22:17:22:21 | ... * ... | test.cpp:23:33:23:37 | size1 | $@ in test | test.cpp:22:17:22:21 | ... * ... | here |
16+ | test.cpp:30:27:30:31 | ... * ... | test.cpp:30:27:30:31 | ... * ... | test.cpp:30:27:30:31 | ... * ... | $@ in test | test.cpp:30:27:30:31 | ... * ... | here |
17+ | test.cpp:31:27:31:31 | ... * ... | test.cpp:31:27:31:31 | ... * ... | test.cpp:31:27:31:31 | ... * ... | $@ in test | test.cpp:31:27:31:31 | ... * ... | here |
Original file line number Diff line number Diff line change 1+ experimental/Security/CWE/CWE-190/AllocMultiplicationOverflow.ql
Original file line number Diff line number Diff line change 1+
2+ typedef unsigned long size_t ;
3+ void *malloc (size_t size);
4+
5+ int getAnInt ();
6+
7+ void test ()
8+ {
9+ int x = getAnInt ();
10+ int y = getAnInt ();
11+
12+ char *buffer1 = (char *)malloc (x + y); // GOOD
13+ char *buffer2 = (char *)malloc (x * y); // BAD
14+ int *buffer3 = (int *)malloc (x * sizeof (int )); // GOOD
15+ int *buffer4 = (int *)malloc (x * y * sizeof (int )); // BAD
16+
17+ if ((x <= 1000 ) && (y <= 1000 ))
18+ {
19+ char *buffer5 = (char *)malloc (x * y); // GOOD [FALSE POSITIVE]
20+ }
21+
22+ size_t size1 = x * y;
23+ char *buffer5 = (char *)malloc (size1); // BAD
24+
25+ size_t size2 = x;
26+ size2 *= y;
27+ char *buffer6 = (char *)malloc (size2); // BAD [NOT DETECTED]
28+
29+ char *buffer7 = new char [x * 10 ]; // GOOD
30+ char *buffer8 = new char [x * y]; // BAD
31+ char *buffer9 = new char [x * x]; // BAD
32+ }
You can’t perform that action at this time.
0 commit comments