Skip to content

Commit 69ea7d9

Browse files
authored
Merge pull request github#13790 from MathiasVP/add-invalid-ptr-false-positive
C++: Add false positive to `cpp/invalid-pointer-deref`
2 parents 4f57852 + d905b1e commit 69ea7d9

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ edges
221221
| test.cpp:656:3:656:6 | ... ++ | test.cpp:662:3:662:11 | ... = ... |
222222
| test.cpp:656:3:656:6 | ... ++ | test.cpp:662:3:662:11 | ... = ... |
223223
| test.cpp:667:14:667:31 | new[] | test.cpp:675:7:675:23 | ... = ... |
224+
| test.cpp:695:13:695:26 | new[] | test.cpp:698:5:698:10 | ... += ... |
225+
| test.cpp:698:5:698:10 | ... += ... | test.cpp:701:15:701:16 | * ... |
224226
nodes
225227
| test.cpp:4:15:4:20 | call to malloc | semmle.label | call to malloc |
226228
| test.cpp:5:15:5:22 | ... + ... | semmle.label | ... + ... |
@@ -370,6 +372,9 @@ nodes
370372
| test.cpp:662:3:662:11 | ... = ... | semmle.label | ... = ... |
371373
| test.cpp:667:14:667:31 | new[] | semmle.label | new[] |
372374
| test.cpp:675:7:675:23 | ... = ... | semmle.label | ... = ... |
375+
| test.cpp:695:13:695:26 | new[] | semmle.label | new[] |
376+
| test.cpp:698:5:698:10 | ... += ... | semmle.label | ... += ... |
377+
| test.cpp:701:15:701:16 | * ... | semmle.label | * ... |
373378
subpaths
374379
#select
375380
| test.cpp:6:14:6:15 | * ... | test.cpp:4:15:4:20 | call to malloc | test.cpp:6:14:6:15 | * ... | 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 |
@@ -405,3 +410,4 @@ subpaths
405410
| test.cpp:647:5:647:19 | ... = ... | test.cpp:642:14:642:31 | new[] | test.cpp:647:5:647:19 | ... = ... | 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 |
406411
| test.cpp:662:3:662:11 | ... = ... | test.cpp:652:14:652:27 | new[] | test.cpp:662:3:662:11 | ... = ... | 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 |
407412
| test.cpp:675:7:675:23 | ... = ... | test.cpp:667:14:667:31 | new[] | test.cpp:675:7:675:23 | ... = ... | 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 | ... ++ | ... ++ |
413+
| test.cpp:701:15:701:16 | * ... | test.cpp:695:13:695:26 | new[] | test.cpp:701:15:701:16 | * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:695:13:695:26 | new[] | new[] | test.cpp:696:19:696: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
@@ -689,4 +689,15 @@ void test_missing_call_context_2(unsigned size) {
689689
int* p = new int[size];
690690
int* end_minus_one = pointer_arithmetic(p, size - 1);
691691
*end_minus_one = '0'; // $ deref=L680->L690->L691 // GOOD
692+
}
693+
694+
void test34(unsigned size) {
695+
char *p = new char[size];
696+
char *end = p + size + 1; // $ alloc=L695
697+
if (p + 1 < end) {
698+
p += 1;
699+
}
700+
if (p + 1 < end) {
701+
int val = *p; // $ deref=L698->L700->L701 // GOOD [FALSE POSITIVE]
702+
}
692703
}

0 commit comments

Comments
 (0)