Skip to content

Commit e3aecd3

Browse files
authored
Merge pull request github#13200 from jketema/deref-subpath
C++: Implement the `subpaths` query predicate for `cpp/invalid-pointer-deref`
2 parents 5a1c001 + 014eb25 commit e3aecd3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-193/InvalidPointerDeref.ql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,16 @@ query predicate edges(MergedPathNode node1, MergedPathNode node2) {
345345
joinOn2(node1.asPathNode3(), node2.asSinkNode(), _)
346346
}
347347

348+
query predicate subpaths(
349+
MergedPathNode arg, MergedPathNode par, MergedPathNode ret, MergedPathNode out
350+
) {
351+
AllocToInvalidPointerFlow::PathGraph1::subpaths(arg.asPathNode1(), par.asPathNode1(),
352+
ret.asPathNode1(), out.asPathNode1())
353+
or
354+
InvalidPointerToDerefFlow::PathGraph::subpaths(arg.asPathNode3(), par.asPathNode3(),
355+
ret.asPathNode3(), out.asPathNode3())
356+
}
357+
348358
/**
349359
* Holds if `p1` is a sink of `AllocToInvalidPointerConf` and `p2` is a source
350360
* of `InvalidPointerToDerefConf`, and they are connected through `pai`.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ 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+
subpaths
656657
#select
657658
| 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 |
658659
| 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 |

0 commit comments

Comments
 (0)