Skip to content

Commit 8fb3d83

Browse files
committed
C++: Add FP test case for cpp/invalid-pointer-deref
1 parent 318a60b commit 8fb3d83

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,30 @@ edges
748748
| test.cpp:381:5:381:9 | ... ++ | test.cpp:384:14:384:16 | end |
749749
| test.cpp:381:5:381:9 | ... ++ | test.cpp:384:14:384:16 | end |
750750
| test.cpp:384:14:384:16 | end | test.cpp:384:13:384:16 | Load: * ... |
751+
| test.cpp:388:14:388:27 | new[] | test.cpp:389:16:389:17 | xs |
752+
| test.cpp:388:14:388:27 | new[] | test.cpp:392:5:392:6 | xs |
753+
| test.cpp:389:16:389:17 | xs | test.cpp:392:5:392:8 | ... ++ |
754+
| test.cpp:389:16:389:17 | xs | test.cpp:392:5:392:8 | ... ++ |
755+
| test.cpp:389:16:389:17 | xs | test.cpp:392:5:392:8 | ... ++ |
756+
| test.cpp:389:16:389:17 | xs | test.cpp:392:5:392:8 | ... ++ |
757+
| test.cpp:389:16:389:17 | xs | test.cpp:393:9:393:10 | xs |
758+
| test.cpp:389:16:389:17 | xs | test.cpp:393:9:393:10 | xs |
759+
| test.cpp:392:5:392:8 | ... ++ | test.cpp:392:5:392:8 | ... ++ |
760+
| test.cpp:392:5:392:8 | ... ++ | test.cpp:392:5:392:8 | ... ++ |
761+
| test.cpp:392:5:392:8 | ... ++ | test.cpp:393:9:393:10 | xs |
762+
| test.cpp:392:5:392:8 | ... ++ | test.cpp:393:9:393:10 | xs |
763+
| test.cpp:392:5:392:8 | ... ++ | test.cpp:393:9:393:10 | xs |
764+
| test.cpp:392:5:392:8 | ... ++ | test.cpp:393:9:393:10 | xs |
765+
| test.cpp:392:5:392:8 | ... ++ | test.cpp:395:5:395:6 | xs |
766+
| test.cpp:392:5:392:8 | ... ++ | test.cpp:395:5:395:6 | xs |
767+
| test.cpp:392:5:392:8 | ... ++ | test.cpp:395:5:395:13 | Store: ... = ... |
768+
| test.cpp:392:5:392:8 | ... ++ | test.cpp:395:5:395:13 | Store: ... = ... |
769+
| test.cpp:392:5:392:8 | ... ++ | test.cpp:395:5:395:13 | Store: ... = ... |
770+
| test.cpp:392:5:392:8 | ... ++ | test.cpp:395:5:395:13 | Store: ... = ... |
771+
| test.cpp:393:9:393:10 | xs | test.cpp:395:5:395:6 | xs |
772+
| test.cpp:393:9:393:10 | xs | test.cpp:395:5:395:13 | Store: ... = ... |
773+
| test.cpp:393:9:393:10 | xs | test.cpp:395:5:395:13 | Store: ... = ... |
774+
| test.cpp:395:5:395:6 | xs | test.cpp:395:5:395:13 | Store: ... = ... |
751775
nodes
752776
| test.cpp:4:15:4:20 | call to malloc | semmle.label | call to malloc |
753777
| test.cpp:5:15:5:15 | p | semmle.label | p |
@@ -1087,6 +1111,17 @@ nodes
10871111
| test.cpp:381:5:381:9 | ... ++ | semmle.label | ... ++ |
10881112
| test.cpp:384:13:384:16 | Load: * ... | semmle.label | Load: * ... |
10891113
| test.cpp:384:14:384:16 | end | semmle.label | end |
1114+
| test.cpp:388:14:388:27 | new[] | semmle.label | new[] |
1115+
| test.cpp:389:16:389:17 | xs | semmle.label | xs |
1116+
| test.cpp:392:5:392:6 | xs | semmle.label | xs |
1117+
| test.cpp:392:5:392:8 | ... ++ | semmle.label | ... ++ |
1118+
| test.cpp:392:5:392:8 | ... ++ | semmle.label | ... ++ |
1119+
| test.cpp:392:5:392:8 | ... ++ | semmle.label | ... ++ |
1120+
| test.cpp:392:5:392:8 | ... ++ | semmle.label | ... ++ |
1121+
| test.cpp:393:9:393:10 | xs | semmle.label | xs |
1122+
| test.cpp:393:9:393:10 | xs | semmle.label | xs |
1123+
| test.cpp:395:5:395:6 | xs | semmle.label | xs |
1124+
| test.cpp:395:5:395:13 | Store: ... = ... | semmle.label | Store: ... = ... |
10901125
subpaths
10911126
#select
10921127
| 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 |
@@ -1113,3 +1148,4 @@ subpaths
11131148
| test.cpp:359:14:359:32 | Load: * ... | test.cpp:355:14:355:27 | new[] | test.cpp:359:14:359:32 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@ + 2. | test.cpp:355:14:355:27 | new[] | new[] | test.cpp:356:20:356:23 | size | size |
11141149
| test.cpp:372:15:372:16 | Load: * ... | test.cpp:363:14:363:27 | new[] | test.cpp:372:15:372:16 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:363:14:363:27 | new[] | new[] | test.cpp:365:19:365:22 | size | size |
11151150
| test.cpp:384:13:384:16 | Load: * ... | test.cpp:377:14:377:27 | new[] | test.cpp:384:13:384:16 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:377:14:377:27 | new[] | new[] | test.cpp:378:20:378:23 | size | size |
1151+
| 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 |

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,14 @@ void test27(unsigned size, bool b) {
383383

384384
int val = *end; // BAD
385385
}
386+
387+
void test28(unsigned size) {
388+
char *xs = new char[size];
389+
char *end = &xs[size];
390+
if (xs >= end)
391+
return;
392+
xs++;
393+
if (xs >= end)
394+
return;
395+
xs[0] = 0; // GOOD [FALSE POSITIVE]
396+
}

0 commit comments

Comments
 (0)