Skip to content

Commit 055aea6

Browse files
committed
C++: Add FP caused by missing call context.
1 parent a826c83 commit 055aea6

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,25 @@ edges
10411041
| test.cpp:667:14:667:31 | new[] | test.cpp:675:7:675:8 | xs |
10421042
| test.cpp:675:7:675:8 | xs | test.cpp:675:7:675:19 | access to array |
10431043
| test.cpp:675:7:675:19 | access to array | test.cpp:675:7:675:23 | Store: ... = ... |
1044+
| test.cpp:679:6:679:23 | pointer_arithmetic indirection | test.cpp:690:24:690:41 | call to pointer_arithmetic |
1045+
| test.cpp:679:6:679:23 | pointer_arithmetic indirection | test.cpp:690:24:690:41 | call to pointer_arithmetic |
1046+
| test.cpp:679:30:679:30 | p | test.cpp:680:10:680:10 | p |
1047+
| test.cpp:680:10:680:10 | p | test.cpp:680:10:680:19 | ... + ... |
1048+
| test.cpp:680:10:680:10 | p | test.cpp:680:10:680:19 | ... + ... |
1049+
| test.cpp:680:10:680:19 | ... + ... | test.cpp:679:6:679:23 | pointer_arithmetic indirection |
1050+
| test.cpp:680:10:680:19 | ... + ... | test.cpp:679:6:679:23 | pointer_arithmetic indirection |
1051+
| test.cpp:684:12:684:24 | new[] | test.cpp:685:33:685:33 | p |
1052+
| test.cpp:685:33:685:33 | p | test.cpp:679:30:679:30 | p |
1053+
| test.cpp:689:12:689:24 | new[] | test.cpp:690:43:690:43 | p |
1054+
| test.cpp:690:24:690:41 | call to pointer_arithmetic | test.cpp:690:24:690:41 | call to pointer_arithmetic |
1055+
| test.cpp:690:24:690:41 | call to pointer_arithmetic | test.cpp:691:3:691:16 | * ... |
1056+
| test.cpp:690:24:690:41 | call to pointer_arithmetic | test.cpp:691:3:691:22 | Store: ... = ... |
1057+
| test.cpp:690:24:690:41 | call to pointer_arithmetic | test.cpp:691:3:691:22 | Store: ... = ... |
1058+
| test.cpp:690:24:690:41 | call to pointer_arithmetic | test.cpp:691:3:691:22 | Store: ... = ... |
1059+
| test.cpp:690:24:690:41 | call to pointer_arithmetic | test.cpp:691:4:691:16 | end_minus_one |
1060+
| test.cpp:690:43:690:43 | p | test.cpp:679:30:679:30 | p |
1061+
| test.cpp:691:3:691:16 | * ... | test.cpp:691:3:691:22 | Store: ... = ... |
1062+
| test.cpp:691:4:691:16 | end_minus_one | test.cpp:691:3:691:22 | Store: ... = ... |
10441063
nodes
10451064
| test.cpp:4:15:4:20 | call to malloc | semmle.label | call to malloc |
10461065
| test.cpp:5:15:5:15 | p | semmle.label | p |
@@ -1534,6 +1553,21 @@ nodes
15341553
| test.cpp:675:7:675:8 | xs | semmle.label | xs |
15351554
| test.cpp:675:7:675:19 | access to array | semmle.label | access to array |
15361555
| test.cpp:675:7:675:23 | Store: ... = ... | semmle.label | Store: ... = ... |
1556+
| test.cpp:679:6:679:23 | pointer_arithmetic indirection | semmle.label | pointer_arithmetic indirection |
1557+
| test.cpp:679:30:679:30 | p | semmle.label | p |
1558+
| test.cpp:680:10:680:10 | p | semmle.label | p |
1559+
| test.cpp:680:10:680:19 | ... + ... | semmle.label | ... + ... |
1560+
| test.cpp:680:10:680:19 | ... + ... | semmle.label | ... + ... |
1561+
| test.cpp:684:12:684:24 | new[] | semmle.label | new[] |
1562+
| test.cpp:685:33:685:33 | p | semmle.label | p |
1563+
| test.cpp:689:12:689:24 | new[] | semmle.label | new[] |
1564+
| test.cpp:690:24:690:41 | call to pointer_arithmetic | semmle.label | call to pointer_arithmetic |
1565+
| test.cpp:690:24:690:41 | call to pointer_arithmetic | semmle.label | call to pointer_arithmetic |
1566+
| test.cpp:690:24:690:41 | call to pointer_arithmetic | semmle.label | call to pointer_arithmetic |
1567+
| test.cpp:690:43:690:43 | p | semmle.label | p |
1568+
| test.cpp:691:3:691:16 | * ... | semmle.label | * ... |
1569+
| test.cpp:691:3:691:22 | Store: ... = ... | semmle.label | Store: ... = ... |
1570+
| test.cpp:691:4:691:16 | end_minus_one | semmle.label | end_minus_one |
15371571
subpaths
15381572
#select
15391573
| 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 |
@@ -1569,3 +1603,4 @@ subpaths
15691603
| 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 |
15701604
| 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 |
15711605
| 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 | ... ++ | ... ++ |
1606+
| test.cpp:691:3:691:22 | Store: ... = ... | test.cpp:684:12:684:24 | new[] | test.cpp:691:3:691:22 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:684:12:684:24 | new[] | new[] | test.cpp:680:14:680:19 | offset | offset |

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,3 +675,18 @@ void test33(unsigned size, unsigned src_pos)
675675
xs[dst_pos++] = 0; // GOOD [FALSE POSITIVE]
676676
}
677677
}
678+
679+
int* pointer_arithmetic(int *p, int offset) {
680+
return p + offset;
681+
}
682+
683+
void test_missing_call_context_1(unsigned size) {
684+
int* p = new int[size];
685+
int* end = pointer_arithmetic(p, size);
686+
}
687+
688+
void test_missing_call_context_2(unsigned size) {
689+
int* p = new int[size];
690+
int* end_minus_one = pointer_arithmetic(p, size - 1);
691+
*end_minus_one = '0'; // GOOD [FALSE POSITIVE]
692+
}

0 commit comments

Comments
 (0)