Skip to content

Commit 5a8bed0

Browse files
committed
C++: Add FP for 'cpp/invalid-pointer-deref'.
1 parent f888382 commit 5a8bed0

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,12 @@ edges
575575
| test.cpp:213:6:213:6 | q | test.cpp:213:5:213:13 | Store: ... = ... |
576576
| test.cpp:213:6:213:6 | q | test.cpp:213:5:213:13 | Store: ... = ... |
577577
| test.cpp:221:17:221:22 | call to malloc | test.cpp:222:5:222:5 | p |
578+
| test.cpp:231:18:231:30 | new[] | test.cpp:232:3:232:9 | newname |
579+
| test.cpp:232:3:232:9 | newname | test.cpp:232:3:232:16 | access to array |
580+
| test.cpp:232:3:232:16 | access to array | test.cpp:232:3:232:20 | Store: ... = ... |
581+
| test.cpp:238:20:238:32 | new[] | test.cpp:239:5:239:11 | newname |
582+
| test.cpp:239:5:239:11 | newname | test.cpp:239:5:239:18 | access to array |
583+
| test.cpp:239:5:239:18 | access to array | test.cpp:239:5:239:22 | Store: ... = ... |
578584
#select
579585
| 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 |
580586
| test.cpp:8:14:8:21 | Load: * ... | test.cpp:4:15:4:20 | call to malloc | test.cpp:8:14:8:21 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@ + 1. | test.cpp:4:15:4:20 | call to malloc | call to malloc | test.cpp:5:19:5:22 | size | size |
@@ -593,3 +599,5 @@ edges
593599
| test.cpp:171:9:171:14 | Store: ... = ... | test.cpp:143:18:143:23 | call to malloc | test.cpp:171:9:171:14 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:143:18:143:23 | call to malloc | call to malloc | test.cpp:144:29:144:32 | size | size |
594600
| test.cpp:201:5:201:19 | Store: ... = ... | test.cpp:194:23:194:28 | call to malloc | test.cpp:201:5:201:19 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:194:23:194:28 | call to malloc | call to malloc | test.cpp:195:21:195:23 | len | len |
595601
| test.cpp:213:5:213:13 | Store: ... = ... | test.cpp:205:23:205:28 | call to malloc | test.cpp:213:5:213:13 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:205:23:205:28 | call to malloc | call to malloc | test.cpp:206:21:206:23 | len | len |
602+
| test.cpp:232:3:232:20 | Store: ... = ... | test.cpp:231:18:231:30 | new[] | test.cpp:232:3:232:20 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:231:18:231:30 | new[] | new[] | test.cpp:232:11:232:15 | index | index |
603+
| test.cpp:239:5:239:22 | Store: ... = ... | test.cpp:238:20:238:32 | new[] | test.cpp:239:5:239:22 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:238:20:238:32 | new[] | new[] | test.cpp:239:13:239:17 | index | index |

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,20 @@ void test14(unsigned long n, char *p) {
222222
p[n - 1] = 'a'; // GOOD
223223
}
224224
}
225+
226+
void test15(unsigned index) {
227+
unsigned size = index + 13;
228+
if(size < index) {
229+
return;
230+
}
231+
int* newname = new int[size];
232+
newname[index] = 0; // GOOD [FALSE POSITIVE]
233+
}
234+
235+
void test16(unsigned index) {
236+
unsigned size = index + 13;
237+
if(size >= index) {
238+
int* newname = new int[size];
239+
newname[index] = 0; // GOOD [FALSE POSITIVE]
240+
}
241+
}

0 commit comments

Comments
 (0)