Skip to content

Commit 0e68767

Browse files
committed
C++: Add more cpp/invalid-pointer-deref FPs
1 parent 8fb3d83 commit 0e68767

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,19 @@ edges
772772
| test.cpp:393:9:393:10 | xs | test.cpp:395:5:395:13 | Store: ... = ... |
773773
| test.cpp:393:9:393:10 | xs | test.cpp:395:5:395:13 | Store: ... = ... |
774774
| test.cpp:395:5:395:6 | xs | test.cpp:395:5:395:13 | Store: ... = ... |
775+
| test.cpp:404:3:404:25 | ... = ... | test.cpp:404:7:404:8 | val indirection [post update] [xs] |
776+
| test.cpp:404:7:404:8 | val indirection [post update] [xs] | test.cpp:407:3:407:5 | val indirection [xs] |
777+
| test.cpp:404:12:404:25 | new[] | test.cpp:404:3:404:25 | ... = ... |
778+
| test.cpp:406:3:406:25 | ... = ... | test.cpp:406:7:406:8 | val indirection [post update] [xs] |
779+
| test.cpp:406:7:406:8 | val indirection [post update] [xs] | test.cpp:407:3:407:5 | val indirection [xs] |
780+
| test.cpp:406:12:406:25 | new[] | test.cpp:406:3:406:25 | ... = ... |
781+
| test.cpp:407:3:407:5 | val indirection [xs] | test.cpp:407:7:407:8 | xs indirection |
782+
| test.cpp:407:3:407:18 | access to array | test.cpp:407:3:407:22 | Store: ... = ... |
783+
| test.cpp:407:7:407:8 | xs | test.cpp:407:3:407:18 | access to array |
784+
| test.cpp:407:7:407:8 | xs indirection | test.cpp:407:7:407:8 | xs |
785+
| test.cpp:417:16:417:33 | new[] | test.cpp:419:7:419:8 | xs |
786+
| test.cpp:419:7:419:8 | xs | test.cpp:419:7:419:11 | access to array |
787+
| test.cpp:419:7:419:11 | access to array | test.cpp:419:7:419:15 | Store: ... = ... |
775788
nodes
776789
| test.cpp:4:15:4:20 | call to malloc | semmle.label | call to malloc |
777790
| test.cpp:5:15:5:15 | p | semmle.label | p |
@@ -1122,6 +1135,21 @@ nodes
11221135
| test.cpp:393:9:393:10 | xs | semmle.label | xs |
11231136
| test.cpp:395:5:395:6 | xs | semmle.label | xs |
11241137
| test.cpp:395:5:395:13 | Store: ... = ... | semmle.label | Store: ... = ... |
1138+
| test.cpp:404:3:404:25 | ... = ... | semmle.label | ... = ... |
1139+
| test.cpp:404:7:404:8 | val indirection [post update] [xs] | semmle.label | val indirection [post update] [xs] |
1140+
| test.cpp:404:12:404:25 | new[] | semmle.label | new[] |
1141+
| test.cpp:406:3:406:25 | ... = ... | semmle.label | ... = ... |
1142+
| test.cpp:406:7:406:8 | val indirection [post update] [xs] | semmle.label | val indirection [post update] [xs] |
1143+
| test.cpp:406:12:406:25 | new[] | semmle.label | new[] |
1144+
| test.cpp:407:3:407:5 | val indirection [xs] | semmle.label | val indirection [xs] |
1145+
| test.cpp:407:3:407:18 | access to array | semmle.label | access to array |
1146+
| test.cpp:407:3:407:22 | Store: ... = ... | semmle.label | Store: ... = ... |
1147+
| test.cpp:407:7:407:8 | xs | semmle.label | xs |
1148+
| test.cpp:407:7:407:8 | xs indirection | semmle.label | xs indirection |
1149+
| test.cpp:417:16:417:33 | new[] | semmle.label | new[] |
1150+
| test.cpp:419:7:419:8 | xs | semmle.label | xs |
1151+
| test.cpp:419:7:419:11 | access to array | semmle.label | access to array |
1152+
| test.cpp:419:7:419:15 | Store: ... = ... | semmle.label | Store: ... = ... |
11251153
subpaths
11261154
#select
11271155
| 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 |
@@ -1149,3 +1177,5 @@ subpaths
11491177
| 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 |
11501178
| 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 |
11511179
| 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 |
1180+
| test.cpp:407:3:407:22 | Store: ... = ... | test.cpp:404:12:404:25 | new[] | test.cpp:407:3:407:22 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:404:12:404:25 | new[] | new[] | test.cpp:407:10:407:17 | ... - ... | ... - ... |
1181+
| test.cpp:419:7:419:15 | Store: ... = ... | test.cpp:417:16:417:33 | new[] | test.cpp:419:7:419:15 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:417:16:417:33 | new[] | new[] | test.cpp:419:10:419:10 | i | i |

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,30 @@ void test28(unsigned size) {
394394
return;
395395
xs[0] = 0; // GOOD [FALSE POSITIVE]
396396
}
397+
398+
struct test29_struct {
399+
char* xs;
400+
};
401+
402+
void test29(unsigned size) {
403+
test29_struct val;
404+
val.xs = new char[size];
405+
size++;
406+
val.xs = new char[size];
407+
val.xs[size - 1] = 0; // GOOD [FALSE POSITIVE]
408+
}
409+
410+
void test30(int *size)
411+
{
412+
int new_size = 0, tmp_size = 0;
413+
414+
test30(&tmp_size);
415+
if (tmp_size + 1 > new_size) {
416+
new_size = tmp_size + 1;
417+
char *xs = new char[new_size];
418+
for (int i = 0; i < new_size; i++) {
419+
xs[i] = 0; // GOOD [FALSE POSITIVE]
420+
}
421+
}
422+
*size = new_size;
423+
}

0 commit comments

Comments
 (0)