Skip to content

Commit 2a514d6

Browse files
committed
C++: Add 'isBarrierIn' to prevent path duplication.
1 parent d12a765 commit 2a514d6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ module ProductFlow {
133133
this.isAdditionalFlowStep2(node1, node2)
134134
}
135135

136+
/**
137+
* Holds if data flow into `node` is prohibited in the first projection of the product
138+
* dataflow graph.
139+
*/
140+
predicate isBarrierIn1(DataFlow::Node node) { none() }
141+
142+
/**
143+
* Holds if data flow into `node` is prohibited in the second projection of the product
144+
* dataflow graph.
145+
*/
146+
predicate isBarrierIn2(DataFlow::Node node) { none() }
147+
136148
predicate hasFlowPath(
137149
DataFlow::PathNode source1, DataFlow2::PathNode source2, DataFlow::PathNode sink1,
138150
DataFlow2::PathNode sink2
@@ -169,6 +181,10 @@ module ProductFlow {
169181
) {
170182
exists(Configuration conf | conf.isAdditionalFlowStep1(node1, state1, node2, state2))
171183
}
184+
185+
override predicate isBarrierIn(DataFlow::Node node) {
186+
exists(Configuration conf | conf.isBarrierIn1(node))
187+
}
172188
}
173189

174190
class Conf2 extends DataFlow2::Configuration {
@@ -202,9 +218,14 @@ module ProductFlow {
202218
) {
203219
exists(Configuration conf | conf.isAdditionalFlowStep2(node1, state1, node2, state2))
204220
}
221+
222+
override predicate isBarrierIn(DataFlow::Node node) {
223+
exists(Configuration conf | conf.isBarrierIn2(node))
224+
}
205225
}
206226
}
207227

228+
pragma[nomagic]
208229
private predicate reachableInterprocEntry(
209230
Configuration conf, DataFlow::PathNode source1, DataFlow2::PathNode source2,
210231
DataFlow::PathNode node1, DataFlow2::PathNode node2

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class AllocToInvalidPointerConf extends ProductFlow::Configuration {
132132
override predicate isBarrierOut2(DataFlow::Node node) {
133133
node = any(DataFlow::SsaPhiNode phi).getAnInput(true)
134134
}
135+
136+
override predicate isBarrierIn1(DataFlow::Node node) { isSourcePair(node, _, _, _) }
135137
}
136138

137139
pragma[nomagic]

0 commit comments

Comments
 (0)