Skip to content

Commit 8a2d485

Browse files
committed
C++: Add another testcase.
1 parent bc0b2e5 commit 8a2d485

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ edges
180180
| test.cpp:815:52:815:54 | end | test.cpp:821:7:821:12 | ... = ... |
181181
| test.cpp:832:40:832:43 | mk_array_no_field_flow output argument | test.cpp:833:37:833:39 | end |
182182
| test.cpp:833:37:833:39 | end | test.cpp:815:52:815:54 | end |
183+
| test.cpp:841:18:841:35 | call to malloc | test.cpp:842:3:842:20 | ... = ... |
184+
| test.cpp:848:20:848:37 | call to malloc | test.cpp:849:5:849:22 | ... = ... |
183185
nodes
184186
| test.cpp:4:15:4:33 | call to malloc | semmle.label | call to malloc |
185187
| test.cpp:5:15:5:22 | ... + ... | semmle.label | ... + ... |
@@ -304,6 +306,10 @@ nodes
304306
| test.cpp:821:7:821:12 | ... = ... | semmle.label | ... = ... |
305307
| test.cpp:832:40:832:43 | mk_array_no_field_flow output argument | semmle.label | mk_array_no_field_flow output argument |
306308
| test.cpp:833:37:833:39 | end | semmle.label | end |
309+
| test.cpp:841:18:841:35 | call to malloc | semmle.label | call to malloc |
310+
| test.cpp:842:3:842:20 | ... = ... | semmle.label | ... = ... |
311+
| test.cpp:848:20:848:37 | call to malloc | semmle.label | call to malloc |
312+
| test.cpp:849:5:849:22 | ... = ... | semmle.label | ... = ... |
307313
subpaths
308314
#select
309315
| test.cpp:6:14:6:15 | * ... | test.cpp:4:15:4:33 | 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:33 | call to malloc | call to malloc | test.cpp:5:19:5:22 | size | size |
@@ -340,3 +346,5 @@ subpaths
340346
| test.cpp:786:18:786:27 | access to array | test.cpp:781:14:781:27 | new[] | test.cpp:786:18:786:27 | access to array | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:781:14:781:27 | new[] | new[] | test.cpp:786:20:786:26 | ... + ... | ... + ... |
341347
| test.cpp:807:7:807:12 | ... = ... | test.cpp:793:14:793:32 | call to malloc | test.cpp:807:7:807:12 | ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:793:14:793:32 | call to malloc | call to malloc | test.cpp:794:21:794:24 | size | size |
342348
| test.cpp:821:7:821:12 | ... = ... | test.cpp:793:14:793:32 | call to malloc | test.cpp:821:7:821:12 | ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:793:14:793:32 | call to malloc | call to malloc | test.cpp:794:21:794:24 | size | size |
349+
| test.cpp:842:3:842:20 | ... = ... | test.cpp:841:18:841:35 | call to malloc | test.cpp:842:3:842:20 | ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:841:18:841:35 | call to malloc | call to malloc | test.cpp:842:11:842:15 | index | index |
350+
| test.cpp:849:5:849:22 | ... = ... | test.cpp:848:20:848:37 | call to malloc | test.cpp:849:5:849:22 | ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:848:20:848:37 | call to malloc | call to malloc | test.cpp:849:13:849:17 | index | index |

cpp/ql/test/query-tests/Security/CWE/CWE-193/test.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,3 +832,20 @@ void test7_no_field_flow(int size) {
832832
mk_array_no_field_flow(size, &begin, &end);
833833
test7_callee_no_field_flow(begin, end);
834834
}
835+
836+
void test15_with_malloc(unsigned long index) {
837+
unsigned long size = index + 13;
838+
if(size < index) {
839+
return;
840+
}
841+
int* newname = (int*)malloc(size);
842+
newname[index] = 0; // $ SPURIOUS: alloc=L841 deref=L842 // GOOD [FALSE POSITIVE]
843+
}
844+
845+
void test16_with_malloc(unsigned long index) {
846+
unsigned long size = index + 13;
847+
if(size >= index) {
848+
int* newname = (int*)malloc(size);
849+
newname[index] = 0; // $ SPURIOUS: alloc=L848 deref=L849 // GOOD [FALSE POSITIVE]
850+
}
851+
}

0 commit comments

Comments
 (0)