Skip to content

Commit 3f289b1

Browse files
committed
C++: Add cpp/invalid-pointer-deref false positives
1 parent 05c30e8 commit 3f289b1

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,31 @@ edges
653653
| test.cpp:304:15:304:26 | new[] | test.cpp:308:5:308:6 | xs |
654654
| test.cpp:308:5:308:6 | xs | test.cpp:308:5:308:11 | access to array |
655655
| test.cpp:308:5:308:11 | access to array | test.cpp:308:5:308:29 | Store: ... = ... |
656+
| test.cpp:313:16:313:29 | new[] | test.cpp:314:17:314:18 | xs |
657+
| test.cpp:314:17:314:18 | xs | test.cpp:314:17:314:25 | ... + ... |
658+
| test.cpp:314:17:314:18 | xs | test.cpp:314:17:314:25 | ... + ... |
659+
| test.cpp:314:17:314:18 | xs | test.cpp:318:13:318:20 | * ... |
660+
| test.cpp:314:17:314:25 | ... + ... | test.cpp:318:14:318:20 | current |
661+
| test.cpp:314:17:314:25 | ... + ... | test.cpp:318:14:318:20 | current |
662+
| test.cpp:314:17:314:25 | ... + ... | test.cpp:320:13:320:20 | * ... |
663+
| test.cpp:314:17:314:25 | ... + ... | test.cpp:320:13:320:20 | * ... |
664+
| test.cpp:314:17:314:25 | ... + ... | test.cpp:320:14:320:20 | current |
665+
| test.cpp:314:17:314:25 | ... + ... | test.cpp:320:14:320:20 | current |
666+
| test.cpp:318:13:318:20 | * ... | test.cpp:318:14:318:20 | current |
667+
| test.cpp:318:13:318:20 | * ... | test.cpp:320:13:320:20 | * ... |
668+
| test.cpp:318:13:318:20 | * ... | test.cpp:320:14:320:20 | current |
669+
| test.cpp:318:14:318:20 | current | test.cpp:314:17:314:25 | Store: ... + ... |
670+
| test.cpp:318:14:318:20 | current | test.cpp:318:13:318:20 | Load: * ... |
671+
| test.cpp:318:14:318:20 | current | test.cpp:320:10:320:21 | Store: -- ... |
672+
| test.cpp:318:14:318:20 | current | test.cpp:320:12:320:21 | Load: (...) |
673+
| test.cpp:320:13:320:20 | * ... | test.cpp:314:17:314:25 | Store: ... + ... |
674+
| test.cpp:320:13:320:20 | * ... | test.cpp:318:13:318:20 | Load: * ... |
675+
| test.cpp:320:13:320:20 | * ... | test.cpp:320:10:320:21 | Store: -- ... |
676+
| test.cpp:320:13:320:20 | * ... | test.cpp:320:12:320:21 | Load: (...) |
677+
| test.cpp:320:14:320:20 | current | test.cpp:314:17:314:25 | Store: ... + ... |
678+
| test.cpp:320:14:320:20 | current | test.cpp:318:13:318:20 | Load: * ... |
679+
| test.cpp:320:14:320:20 | current | test.cpp:320:10:320:21 | Store: -- ... |
680+
| test.cpp:320:14:320:20 | current | test.cpp:320:12:320:21 | Load: (...) |
656681
subpaths
657682
#select
658683
| 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 |
@@ -678,3 +703,7 @@ subpaths
678703
| test.cpp:264:13:264:14 | Load: * ... | test.cpp:260:13:260:24 | new[] | test.cpp:264:13:264:14 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:260:13:260:24 | new[] | new[] | test.cpp:261:19:261:21 | len | len |
679704
| test.cpp:274:5:274:10 | Store: ... = ... | test.cpp:270:13:270:24 | new[] | test.cpp:274:5:274:10 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:270:13:270:24 | new[] | new[] | test.cpp:271:19:271:21 | len | len |
680705
| test.cpp:308:5:308:29 | Store: ... = ... | test.cpp:304:15:304:26 | new[] | test.cpp:308:5:308:29 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:304:15:304:26 | new[] | new[] | test.cpp:308:8:308:10 | ... + ... | ... + ... |
706+
| test.cpp:314:17:314:25 | Store: ... + ... | test.cpp:313:16:313:29 | new[] | test.cpp:314:17:314:25 | Store: ... + ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:313:16:313:29 | new[] | new[] | test.cpp:314:22:314:25 | size | size |
707+
| test.cpp:318:13:318:20 | Load: * ... | test.cpp:313:16:313:29 | new[] | test.cpp:318:13:318:20 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:313:16:313:29 | new[] | new[] | test.cpp:314:22:314:25 | size | size |
708+
| test.cpp:320:10:320:21 | Store: -- ... | test.cpp:313:16:313:29 | new[] | test.cpp:320:10:320:21 | Store: -- ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:313:16:313:29 | new[] | new[] | test.cpp:314:22:314:25 | size | size |
709+
| test.cpp:320:12:320:21 | Load: (...) | test.cpp:313:16:313:29 | new[] | test.cpp:320:12:320:21 | Load: (...) | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:313:16:313:29 | new[] | new[] | test.cpp:314:22:314:25 | size | size |

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,17 @@ void test21() {
308308
xs[i+1] = test21_get(i+1); // GOOD [FALSE POSITIVE]
309309
}
310310
}
311+
312+
void test22(unsigned size, int val) {
313+
char *xs = new char[size];
314+
char *end = xs + size; // GOOD [FALSE POSITIVE]
315+
char **current = &end;
316+
do
317+
{
318+
if( *current - xs < 1 ) // GOOD [FALSE POSITIVE]
319+
return;
320+
*--(*current) = 0; // GOOD [FALSE POSITIVE]
321+
val >>= 8;
322+
}
323+
while( val > 0 );
324+
}

0 commit comments

Comments
 (0)