Skip to content

Commit 9ff5754

Browse files
committed
C++: Add cpp/invalid-pointer-def FP test case
1 parent 0e68767 commit 9ff5754

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,9 @@ edges
785785
| test.cpp:417:16:417:33 | new[] | test.cpp:419:7:419:8 | xs |
786786
| test.cpp:419:7:419:8 | xs | test.cpp:419:7:419:11 | access to array |
787787
| test.cpp:419:7:419:11 | access to array | test.cpp:419:7:419:15 | Store: ... = ... |
788+
| test.cpp:427:14:427:27 | new[] | test.cpp:433:5:433:6 | xs |
789+
| test.cpp:433:5:433:6 | xs | test.cpp:433:5:433:17 | access to array |
790+
| test.cpp:433:5:433:17 | access to array | test.cpp:433:5:433:21 | Store: ... = ... |
788791
nodes
789792
| test.cpp:4:15:4:20 | call to malloc | semmle.label | call to malloc |
790793
| test.cpp:5:15:5:15 | p | semmle.label | p |
@@ -1150,6 +1153,10 @@ nodes
11501153
| test.cpp:419:7:419:8 | xs | semmle.label | xs |
11511154
| test.cpp:419:7:419:11 | access to array | semmle.label | access to array |
11521155
| test.cpp:419:7:419:15 | Store: ... = ... | semmle.label | Store: ... = ... |
1156+
| test.cpp:427:14:427:27 | new[] | semmle.label | new[] |
1157+
| test.cpp:433:5:433:6 | xs | semmle.label | xs |
1158+
| test.cpp:433:5:433:17 | access to array | semmle.label | access to array |
1159+
| test.cpp:433:5:433:21 | Store: ... = ... | semmle.label | Store: ... = ... |
11531160
subpaths
11541161
#select
11551162
| test.cpp:6:14:6:15 | Load: * ... | test.cpp:4:15:4:20 | call to malloc | test.cpp:6:14:6:15 | Load: * ... | 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 |
@@ -1179,3 +1186,4 @@ subpaths
11791186
| test.cpp:395:5:395:13 | Store: ... = ... | test.cpp:388:14:388:27 | new[] | test.cpp:395:5:395:13 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:388:14:388:27 | new[] | new[] | test.cpp:389:19:389:22 | size | size |
11801187
| test.cpp:407:3:407:22 | Store: ... = ... | test.cpp:404:12:404:25 | new[] | test.cpp:407:3:407:22 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:404:12:404:25 | new[] | new[] | test.cpp:407:10:407:17 | ... - ... | ... - ... |
11811188
| test.cpp:419:7:419:15 | Store: ... = ... | test.cpp:417:16:417:33 | new[] | test.cpp:419:7:419:15 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:417:16:417:33 | new[] | new[] | test.cpp:419:10:419:10 | i | i |
1189+
| test.cpp:433:5:433:21 | Store: ... = ... | test.cpp:427:14:427:27 | new[] | test.cpp:433:5:433:21 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:427:14:427:27 | new[] | new[] | test.cpp:433:8:433:16 | ... ++ | ... ++ |

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,15 @@ void test30(int *size)
421421
}
422422
*size = new_size;
423423
}
424+
425+
void test31(unsigned size, unsigned src_pos)
426+
{
427+
char *xs = new char[size];
428+
if (src_pos > size) {
429+
src_pos = size;
430+
}
431+
unsigned dst_pos = src_pos;
432+
if(dst_pos < size - 3) {
433+
xs[dst_pos++] = 0; // GOOD [FALSE POSITIVE]
434+
}
435+
}

0 commit comments

Comments
 (0)