Skip to content

Commit 768c03a

Browse files
committed
unified: Bypass Optional<T> content
1 parent 6efb2a1 commit 768c03a

4 files changed

Lines changed: 45 additions & 4 deletions

File tree

‎unified/ql/lib/codeql/unified/internal/dataflow/DataFlowGraph.qll‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,26 @@ module DebugGraph<relevantNodeSig/1 relevantNode> {
176176
value = node.toString()
177177
}
178178

179+
private predicate isBypassedStoreReadStep(Step s) {
180+
exists(ContentSet contents |
181+
s.read(contents)
182+
or
183+
s.store(contents)
184+
|
185+
bypassContentSet(contents)
186+
)
187+
}
188+
179189
query predicate edges(Node node1, Node node2, string key, string value) {
180190
key = "semmle.label" and
181191
relevantDataFlowNode(node1) and
182192
relevantDataFlowNode(node2) and
183193
(
184194
exists(Step step |
185195
step(node1, step, node2) and
186-
value = step.toString()
196+
if isBypassedStoreReadStep(step)
197+
then value = "value [bypassed " + step.toString() + "]"
198+
else value = step.toString()
187199
)
188200
or
189201
exists(boolean isUseStep |

‎unified/ql/lib/codeql/unified/internal/dataflow/DataFlowInstantiation.qll‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,33 @@ module DataFlowInput implements InputSig<Location> {
127127
//
128128
// Steps
129129
//
130+
pragma[nomagic]
131+
private Step valueStepEx() {
132+
result.value()
133+
or
134+
exists(ContentSet contents | bypassContentSet(contents) |
135+
result.read(contents)
136+
or
137+
result.store(contents)
138+
)
139+
}
140+
130141
predicate simpleLocalFlowStep(Node node1, Node node2, string model) {
131-
step(node1, any(Step s | s.value()), node2) and model = ""
142+
step(node1, valueStepEx(), node2) and model = ""
132143
or
133144
localSsaStep(node1, node2, _) and model = ""
134145
}
135146

136147
predicate jumpStep(Node node1, Node node2) { step(node1, any(Step s | s.jump()), node2) }
137148

138149
predicate readStep(Node node1, ContentSet c, Node node2) {
139-
step(node1, any(Step s | s.read(c)), node2)
150+
step(node1, any(Step s | s.read(c)), node2) and
151+
not bypassContentSet(c)
140152
}
141153

142154
predicate storeStep(Node node1, ContentSet c, Node node2) {
143-
step(node1, any(Step s | s.store(c)), node2)
155+
step(node1, any(Step s | s.store(c)), node2) and
156+
not bypassContentSet(c)
144157
}
145158

146159
predicate clearsContent(Node n, ContentSet c) { none() } // TODO

‎unified/ql/lib/codeql/unified/internal/dataflow/DataFlowPlugin.qll‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,16 @@ private module Plugins {
1313
class DataFlowPlugin extends Unit {
1414
/** Holds if there is a language-specific step from `node1 -> step -> node2`. */
1515
predicate step(Node node1, Step step, Node node2) { none() }
16+
17+
/**
18+
* Holds if a read/store step with the given `contents` should be converted to a value step.
19+
*
20+
* This affects the steps generated by the language-agnostic code as well as steps from the plugin itself.
21+
*/
22+
predicate bypassContentSet(ContentSet contents) { none() }
1623
}
24+
25+
/**
26+
* Holds if a read/store step with the given `contents` should be converted to a value step.
27+
*/
28+
predicate bypassContentSet(ContentSet contents) { any(DataFlowPlugin p).bypassContentSet(contents) }

‎unified/ql/lib/codeql/unified/internal/dataflow/DataFlowPluginSwift.qll‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ private import unified
66
private import AllDataFlow
77

88
private class SwiftDataFlowPlugin extends DataFlowPlugin {
9+
override predicate bypassContentSet(ContentSet contents) {
10+
contents.asSingleton().asNamedMember() = "some.0"
11+
}
12+
913
// Note: For now we assume all code is Swift, but in the future we must restrict these rules to Swift-files
1014
override predicate step(Node node1, Step step, Node node2) {
1115
exists(BinaryExpr expr |

0 commit comments

Comments
 (0)