Skip to content

Commit 572aa13

Browse files
authored
Merge pull request github#13680 from jketema/product-default
C++: Add more default predicates to product flow
2 parents b2a60bf + 8d05d8a commit 572aa13

File tree

4 files changed

+14
-30
lines changed

4 files changed

+14
-30
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* The `ProductFlow::StateConfigSig` signature now includes default predicates for `isBarrier1`, `isBarrier2`, `isAdditionalFlowStep1`, and `isAdditionalFlowStep1`. Hence, it is no longer needed to provide `none()` implementations of these predicates if they are not needed.

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/ProductFlow.qll

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ module ProductFlow {
192192
* Holds if data flow through `node` is prohibited through the first projection of the product
193193
* dataflow graph when the flow state is `state`.
194194
*/
195-
predicate isBarrier1(DataFlow::Node node, FlowState1 state);
195+
default predicate isBarrier1(DataFlow::Node node, FlowState1 state) { none() }
196196

197197
/**
198198
* Holds if data flow through `node` is prohibited through the second projection of the product
199199
* dataflow graph when the flow state is `state`.
200200
*/
201-
predicate isBarrier2(DataFlow::Node node, FlowState2 state);
201+
default predicate isBarrier2(DataFlow::Node node, FlowState2 state) { none() }
202202

203203
/**
204204
* Holds if data flow through `node` is prohibited through the first projection of the product
@@ -237,9 +237,11 @@ module ProductFlow {
237237
*
238238
* This step is only applicable in `state1` and updates the flow state to `state2`.
239239
*/
240-
predicate isAdditionalFlowStep1(
240+
default predicate isAdditionalFlowStep1(
241241
DataFlow::Node node1, FlowState1 state1, DataFlow::Node node2, FlowState1 state2
242-
);
242+
) {
243+
none()
244+
}
243245

244246
/**
245247
* Holds if data may flow from `node1` to `node2` in addition to the normal data-flow steps in
@@ -253,9 +255,11 @@ module ProductFlow {
253255
*
254256
* This step is only applicable in `state1` and updates the flow state to `state2`.
255257
*/
256-
predicate isAdditionalFlowStep2(
258+
default predicate isAdditionalFlowStep2(
257259
DataFlow::Node node1, FlowState2 state1, DataFlow::Node node2, FlowState2 state2
258-
);
260+
) {
261+
none()
262+
}
259263

260264
/**
261265
* Holds if data flow into `node` is prohibited in the first projection of the product

cpp/ql/src/Security/CWE/CWE-119/OverrunWriteProductFlow.ql

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,20 +248,10 @@ module StringSizeConfig implements ProductFlow::StateConfigSig {
248248
)
249249
}
250250

251-
predicate isBarrier1(DataFlow::Node node, FlowState1 state) { none() }
252-
253-
predicate isBarrier2(DataFlow::Node node, FlowState2 state) { none() }
254-
255251
predicate isBarrierOut2(DataFlow::Node node) {
256252
node = any(DataFlow::SsaPhiNode phi).getAnInput(true)
257253
}
258254

259-
predicate isAdditionalFlowStep1(
260-
DataFlow::Node node1, FlowState1 state1, DataFlow::Node node2, FlowState1 state2
261-
) {
262-
none()
263-
}
264-
265255
predicate isAdditionalFlowStep2(
266256
DataFlow::Node node1, FlowState2 state1, DataFlow::Node node2, FlowState2 state2
267257
) {

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ module AllocToInvalidPointerConfig implements ProductFlow::StateConfigSig {
196196
isSinkImpl(_, sink1, sink2, state2)
197197
}
198198

199-
predicate isBarrier1(DataFlow::Node node, FlowState1 state) { none() }
200-
201199
predicate isBarrier2(DataFlow::Node node, FlowState2 state) {
202200
node = Barrier2::getABarrierNode(state)
203201
}
@@ -207,18 +205,6 @@ module AllocToInvalidPointerConfig implements ProductFlow::StateConfigSig {
207205
predicate isBarrierOut2(DataFlow::Node node) {
208206
node = any(DataFlow::SsaPhiNode phi).getAnInput(true)
209207
}
210-
211-
predicate isAdditionalFlowStep1(
212-
DataFlow::Node node1, FlowState1 state1, DataFlow::Node node2, FlowState1 state2
213-
) {
214-
none()
215-
}
216-
217-
predicate isAdditionalFlowStep2(
218-
DataFlow::Node node1, FlowState2 state1, DataFlow::Node node2, FlowState2 state2
219-
) {
220-
none()
221-
}
222208
}
223209

224210
module AllocToInvalidPointerFlow = ProductFlow::GlobalWithState<AllocToInvalidPointerConfig>;

0 commit comments

Comments
 (0)