Skip to content

Commit 2164069

Browse files
committed
C++: Add another testcase.
1 parent 88d3fcb commit 2164069

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-193/pointer-deref/InvalidPointerDeref.expected

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ edges
222222
| test.cpp:705:18:705:18 | q | test.cpp:706:12:706:13 | * ... |
223223
| test.cpp:711:13:711:26 | new[] | test.cpp:714:11:714:11 | q |
224224
| test.cpp:714:11:714:11 | q | test.cpp:705:18:705:18 | q |
225+
| test.cpp:730:12:730:28 | new[] | test.cpp:732:16:732:26 | ... + ... |
226+
| test.cpp:730:12:730:28 | new[] | test.cpp:732:16:732:26 | ... + ... |
227+
| test.cpp:730:12:730:28 | new[] | test.cpp:733:5:733:12 | ... = ... |
228+
| test.cpp:732:16:732:26 | ... + ... | test.cpp:732:16:732:26 | ... + ... |
229+
| test.cpp:732:16:732:26 | ... + ... | test.cpp:733:5:733:12 | ... = ... |
230+
| test.cpp:732:16:732:26 | ... + ... | test.cpp:733:5:733:12 | ... = ... |
225231
nodes
226232
| test.cpp:4:15:4:20 | call to malloc | semmle.label | call to malloc |
227233
| test.cpp:5:15:5:22 | ... + ... | semmle.label | ... + ... |
@@ -372,6 +378,10 @@ nodes
372378
| test.cpp:706:12:706:13 | * ... | semmle.label | * ... |
373379
| test.cpp:711:13:711:26 | new[] | semmle.label | new[] |
374380
| test.cpp:714:11:714:11 | q | semmle.label | q |
381+
| test.cpp:730:12:730:28 | new[] | semmle.label | new[] |
382+
| test.cpp:732:16:732:26 | ... + ... | semmle.label | ... + ... |
383+
| test.cpp:732:16:732:26 | ... + ... | semmle.label | ... + ... |
384+
| test.cpp:733:5:733:12 | ... = ... | semmle.label | ... = ... |
375385
subpaths
376386
#select
377387
| test.cpp:6:14:6:15 | * ... | test.cpp:4:15:4:20 | call to malloc | test.cpp:6:14:6:15 | * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:4:15:4:20 | call to malloc | call to malloc | test.cpp:5:19:5:22 | size | size |
@@ -406,3 +416,4 @@ subpaths
406416
| test.cpp:647:5:647:19 | ... = ... | test.cpp:642:14:642:31 | new[] | test.cpp:647:5:647:19 | ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:642:14:642:31 | new[] | new[] | test.cpp:647:8:647:14 | src_pos | src_pos |
407417
| test.cpp:701:15:701:16 | * ... | test.cpp:695:13:695:26 | new[] | test.cpp:701:15:701:16 | * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:695:13:695:26 | new[] | new[] | test.cpp:696:19:696:22 | size | size |
408418
| test.cpp:706:12:706:13 | * ... | test.cpp:711:13:711:26 | new[] | test.cpp:706:12:706:13 | * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:711:13:711:26 | new[] | new[] | test.cpp:712:19:712:22 | size | size |
419+
| test.cpp:733:5:733:12 | ... = ... | test.cpp:730:12:730:28 | new[] | test.cpp:733:5:733:12 | ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:730:12:730:28 | new[] | new[] | test.cpp:732:21:732:25 | ... + ... | ... + ... |

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-193/pointer-deref/test.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,4 +724,12 @@ void test21_simple(bool b) {
724724
for (int i = 0; i < n; i += 2) {
725725
xs[i+1] = 0; // GOOD
726726
}
727-
}
727+
}
728+
729+
void test36(unsigned size, unsigned n) {
730+
int* p = new int[size + 2];
731+
if(n < size + 1) {
732+
int* end = p + (n + 2); // $ alloc=L730+2
733+
*end = 0; // $ deref=L733 // BAD
734+
}
735+
}

0 commit comments

Comments
 (0)