Skip to content

Commit dc00643

Browse files
committed
C++: More QLDoc.
1 parent 031f20a commit dc00643

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

cpp/ql/lib/experimental/semmle/code/cpp/dataflow/ProductFlow.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ module ProductFlow {
1313
*/
1414
predicate isSourcePair(DataFlow::Node source1, DataFlow::Node source2) { none() }
1515

16+
/**
17+
* Holds if `(source1, source2)` is a relevant data flow source with initial states `state1`
18+
* and `state2`, respectively.
19+
*
20+
* `source1` and `source2` must belong to the same callable.
21+
*/
1622
predicate isSourcePair(
1723
DataFlow::Node source1, string state1, DataFlow::Node source2, string state2
1824
) {
@@ -28,6 +34,12 @@ module ProductFlow {
2834
*/
2935
predicate isSinkPair(DataFlow::Node sink1, DataFlow::Node sink2) { none() }
3036

37+
/**
38+
* Holds if `(sink1, sink2)` is a relevant data flow sink with final states `state1`
39+
* and `state2`, respectively.
40+
*
41+
* `sink1` and `sink2` must belong to the same callable.
42+
*/
3143
predicate isSinkPair(
3244
DataFlow::Node sink1, DataFlow::FlowState state1, DataFlow::Node sink2,
3345
DataFlow::FlowState state2

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,19 @@ predicate hasSize(AllocationExpr alloc, DataFlow::Node n, string state) {
8686
*
8787
* The goal of this query is to find patterns such as:
8888
* ```cpp
89-
* char* p = (char*)malloc(size);
90-
* char* end = p + size;
91-
* use(*end);
89+
* 1. char* begin = (char*)malloc(size);
90+
* 2. char* end = begin + size;
91+
* 3. for(int *p = begin; p <= end; p++) {
92+
* 4. use(*p);
93+
* 5. }
9294
* ```
9395
*
9496
* We do this by splitting the task up into two configurations:
95-
* 1. `AllocToInvalidPointerConf` find flow from `malloc(size)` to `p + size`, and
96-
* 2. `InvalidPointerToDerefConf` finds flow from `p + size` to `*end`.
97+
* 1. `AllocToInvalidPointerConf` find flow from `malloc(size)` to `begin + size`, and
98+
* 2. `InvalidPointerToDerefConf` finds flow from `begin + size` to an `end` (on line 3).
99+
*
100+
* Finally, the range-analysis library will find a load from (or store to) an address that
101+
* is non-strictly upper-bounded by `end` (which in this case is `*p`).
97102
*/
98103
class AllocToInvalidPointerConf extends ProductFlow::Configuration {
99104
AllocToInvalidPointerConf() { this = "AllocToInvalidPointerConf" }

0 commit comments

Comments
 (0)