Skip to content

Commit f8b1dc9

Browse files
authored
Merge pull request github#13617 from jketema/pointer-deref-barrier-fps
C++: Add more `cpp/invalid-pointer-deref` FP test cases
2 parents e428502 + 2c8d472 commit f8b1dc9

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,25 @@ edges
10221022
| test.cpp:642:14:642:31 | new[] | test.cpp:647:5:647:6 | xs |
10231023
| test.cpp:647:5:647:6 | xs | test.cpp:647:5:647:15 | access to array |
10241024
| test.cpp:647:5:647:15 | access to array | test.cpp:647:5:647:19 | Store: ... = ... |
1025+
| test.cpp:652:14:652:27 | new[] | test.cpp:653:16:653:17 | xs |
1026+
| test.cpp:652:14:652:27 | new[] | test.cpp:656:3:656:4 | xs |
1027+
| test.cpp:653:16:653:17 | xs | test.cpp:656:3:656:6 | ... ++ |
1028+
| test.cpp:653:16:653:17 | xs | test.cpp:656:3:656:6 | ... ++ |
1029+
| test.cpp:653:16:653:17 | xs | test.cpp:656:3:656:6 | ... ++ |
1030+
| test.cpp:653:16:653:17 | xs | test.cpp:656:3:656:6 | ... ++ |
1031+
| test.cpp:653:16:653:17 | xs | test.cpp:657:7:657:8 | xs |
1032+
| test.cpp:656:3:656:6 | ... ++ | test.cpp:656:3:656:6 | ... ++ |
1033+
| test.cpp:656:3:656:6 | ... ++ | test.cpp:656:3:656:6 | ... ++ |
1034+
| test.cpp:656:3:656:6 | ... ++ | test.cpp:657:7:657:8 | xs |
1035+
| test.cpp:656:3:656:6 | ... ++ | test.cpp:657:7:657:8 | xs |
1036+
| test.cpp:656:3:656:6 | ... ++ | test.cpp:662:3:662:11 | Store: ... = ... |
1037+
| test.cpp:656:3:656:6 | ... ++ | test.cpp:662:3:662:11 | Store: ... = ... |
1038+
| test.cpp:656:3:656:6 | ... ++ | test.cpp:662:3:662:11 | Store: ... = ... |
1039+
| test.cpp:656:3:656:6 | ... ++ | test.cpp:662:3:662:11 | Store: ... = ... |
1040+
| test.cpp:657:7:657:8 | xs | test.cpp:662:3:662:11 | Store: ... = ... |
1041+
| test.cpp:667:14:667:31 | new[] | test.cpp:675:7:675:8 | xs |
1042+
| test.cpp:675:7:675:8 | xs | test.cpp:675:7:675:19 | access to array |
1043+
| test.cpp:675:7:675:19 | access to array | test.cpp:675:7:675:23 | Store: ... = ... |
10251044
nodes
10261045
| test.cpp:4:15:4:20 | call to malloc | semmle.label | call to malloc |
10271046
| test.cpp:5:15:5:15 | p | semmle.label | p |
@@ -1502,6 +1521,19 @@ nodes
15021521
| test.cpp:647:5:647:6 | xs | semmle.label | xs |
15031522
| test.cpp:647:5:647:15 | access to array | semmle.label | access to array |
15041523
| test.cpp:647:5:647:19 | Store: ... = ... | semmle.label | Store: ... = ... |
1524+
| test.cpp:652:14:652:27 | new[] | semmle.label | new[] |
1525+
| test.cpp:653:16:653:17 | xs | semmle.label | xs |
1526+
| test.cpp:656:3:656:4 | xs | semmle.label | xs |
1527+
| test.cpp:656:3:656:6 | ... ++ | semmle.label | ... ++ |
1528+
| test.cpp:656:3:656:6 | ... ++ | semmle.label | ... ++ |
1529+
| test.cpp:656:3:656:6 | ... ++ | semmle.label | ... ++ |
1530+
| test.cpp:656:3:656:6 | ... ++ | semmle.label | ... ++ |
1531+
| test.cpp:657:7:657:8 | xs | semmle.label | xs |
1532+
| test.cpp:662:3:662:11 | Store: ... = ... | semmle.label | Store: ... = ... |
1533+
| test.cpp:667:14:667:31 | new[] | semmle.label | new[] |
1534+
| test.cpp:675:7:675:8 | xs | semmle.label | xs |
1535+
| test.cpp:675:7:675:19 | access to array | semmle.label | access to array |
1536+
| test.cpp:675:7:675:23 | Store: ... = ... | semmle.label | Store: ... = ... |
15051537
subpaths
15061538
#select
15071539
| 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 |
@@ -1535,3 +1567,5 @@ subpaths
15351567
| test.cpp:548:5:548:19 | Store: ... = ... | test.cpp:543:14:543:27 | new[] | test.cpp:548:5:548:19 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:543:14:543:27 | new[] | new[] | test.cpp:548:8:548:14 | src_pos | src_pos |
15361568
| test.cpp:559:5:559:19 | Store: ... = ... | test.cpp:554:14:554:27 | new[] | test.cpp:559:5:559:19 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:554:14:554:27 | new[] | new[] | test.cpp:559:8:559:14 | src_pos | src_pos |
15371569
| test.cpp:647:5:647:19 | Store: ... = ... | test.cpp:642:14:642:31 | new[] | test.cpp:647:5:647:19 | Store: ... = ... | 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 |
1570+
| test.cpp:662:3:662:11 | Store: ... = ... | test.cpp:652:14:652:27 | new[] | test.cpp:662:3:662:11 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@ + 1. | test.cpp:652:14:652:27 | new[] | new[] | test.cpp:653:19:653:22 | size | size |
1571+
| test.cpp:675:7:675:23 | Store: ... = ... | test.cpp:667:14:667:31 | new[] | test.cpp:675:7:675:23 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:667:14:667:31 | new[] | new[] | test.cpp:675:10:675:18 | ... ++ | ... ++ |

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,3 +647,31 @@ void test31_simple1_sub1(unsigned size, unsigned src_pos)
647647
xs[src_pos] = 0; // BAD
648648
}
649649
}
650+
651+
void test32(unsigned size) {
652+
char *xs = new char[size];
653+
char *end = &xs[size];
654+
if (xs >= end)
655+
return;
656+
xs++;
657+
if (xs >= end)
658+
return;
659+
xs++;
660+
if (xs >= end)
661+
return;
662+
xs[0] = 0; // GOOD [FALSE POSITIVE]
663+
}
664+
665+
void test33(unsigned size, unsigned src_pos)
666+
{
667+
char *xs = new char[size + 1];
668+
if (src_pos > size) {
669+
src_pos = size;
670+
}
671+
unsigned dst_pos = src_pos;
672+
while (dst_pos < size - 1) {
673+
dst_pos++;
674+
if (true)
675+
xs[dst_pos++] = 0; // GOOD [FALSE POSITIVE]
676+
}
677+
}

0 commit comments

Comments
 (0)