Skip to content

Commit 0207607

Browse files
committed
C++: Add more comments.
1 parent 3e6576b commit 0207607

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ class AllocToInvalidPointerConf extends ProductFlow::Configuration {
106106
override predicate isSourcePair(
107107
DataFlow::Node source1, string state1, DataFlow::Node source2, string state2
108108
) {
109+
// In the case of an allocation like
110+
// ```cpp
111+
// malloc(size + 1);
112+
// ```
113+
// we use `state2` to remember that there was an offset (in this case an offset of `1`) added
114+
// to the size of the allocation. This state is then checked in `isSinkPair`.
109115
state1 = "" and
110116
hasSize(source1.asConvertedExpr(), source2, state2)
111117
}
@@ -115,6 +121,8 @@ class AllocToInvalidPointerConf extends ProductFlow::Configuration {
115121
DataFlow::FlowState state2
116122
) {
117123
state1 = "" and
124+
// We check that the delta computed by the range analysis matches the
125+
// state value that we set in `isSourcePair`.
118126
exists(int delta |
119127
isSinkImpl(_, sink1, sink2, delta) and
120128
state2 = delta.toString()

0 commit comments

Comments
 (0)