Skip to content

Commit 4f413e8

Browse files
committed
Swift: Adapt to FlowSummaryImpl changes
1 parent 9f13c7c commit 4f413e8

3 files changed

Lines changed: 53 additions & 19 deletions

File tree

swift/ql/lib/codeql/swift/dataflow/internal/DataFlowPrivate.qll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,7 @@ private module Cached {
305305
model = ""
306306
or
307307
// flow through a flow summary (extension of `SummaryModelCsv`)
308-
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom,
309-
nodeTo.(FlowSummaryNode).getSummaryNode(), true, model)
308+
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, true, model)
310309
}
311310

312311
/**
@@ -497,10 +496,10 @@ class FlowSummaryNode extends NodeImpl, TFlowSummaryNode {
497496
}
498497

499498
override DataFlowCallable getEnclosingCallable() {
500-
result.asSummarizedCallable() = this.getSummarizedCallable()
499+
result = this.getSummaryNode().getEnclosingCallable()
501500
}
502501

503-
override Location getLocationImpl() { result = this.getSummarizedCallable().getLocation() }
502+
override Location getLocationImpl() { result = this.getSummaryNode().getLocation() }
504503

505504
override string toStringImpl() { result = this.getSummaryNode().toString() }
506505
}
@@ -1014,8 +1013,7 @@ predicate captureValueStep(Node node1, Node node2) {
10141013

10151014
predicate jumpStep(Node pred, Node succ) {
10161015
// models-as-data summarized flow
1017-
FlowSummaryImpl::Private::Steps::summaryJumpStep(pred.(FlowSummaryNode).getSummaryNode(),
1018-
succ.(FlowSummaryNode).getSummaryNode())
1016+
FlowSummaryImpl::Private::Steps::summaryJumpStep(pred, succ)
10191017
}
10201018

10211019
predicate storeStep(Node node1, ContentSet c, Node node2) {

swift/ql/lib/codeql/swift/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ module Input implements InputSig<Location, DataFlowImplSpecific::SwiftDataFlow>
1616

1717
class SummarizedCallableBase = Function;
1818

19-
class SourceBase = Void;
19+
class SourceBase extends Void {
20+
Location getLocation() { none() }
21+
}
2022

21-
class SinkBase = Void;
23+
class SinkBase = SourceBase;
2224

23-
class FlowSummaryCallBase = Void;
25+
class FlowSummaryCallBase = SourceBase;
2426

2527
predicate callableFromSource(SummarizedCallableBase c) { c.hasBody() }
2628

29+
DataFlowCallable getSummarizedCallableAsDataFlowCallable(SummarizedCallableBase c) {
30+
result.asSummarizedCallable() = c
31+
}
32+
2733
ArgumentPosition callbackSelfParameterPosition() { result instanceof ThisArgumentPosition }
2834

2935
ReturnKind getStandardReturnValueKind() { result instanceof NormalReturnKind }
@@ -114,18 +120,48 @@ module Input implements InputSig<Location, DataFlowImplSpecific::SwiftDataFlow>
114120

115121
private import Make<Location, DataFlowImplSpecific::SwiftDataFlow, Input> as Impl
116122

117-
private module StepsInput implements Impl::Private::StepsInputSig {
118-
Impl::Private::SummaryNode getSummaryNode(Node n) {
119-
result = n.(FlowSummaryNode).getSummaryNode()
123+
private module Input2 implements Impl::Private::InputSig2 {
124+
private import codeql.util.Void
125+
126+
class SourceSinkReportingElement extends Void {
127+
Location getLocation() { none() }
128+
129+
DataFlowCallable getEnclosingCallable() { none() }
120130
}
121131

122-
DataFlowCall getACall(Public::SummarizedCallable sc) { result.asCall().getStaticTarget() = sc }
132+
SourceSinkReportingElement getSourceEntryElement(
133+
Impl::Public::SourceElement source, Impl::Private::SummaryComponent sc
134+
) {
135+
none()
136+
}
137+
138+
SourceSinkReportingElement getNextElement(
139+
SourceSinkReportingElement prev, Impl::Private::SummaryComponent sc
140+
) {
141+
none()
142+
}
143+
144+
bindingset[e, sc]
145+
Node getSourceExitNode(SourceSinkReportingElement e, Impl::Private::SummaryComponent sc) {
146+
none()
147+
}
148+
149+
SourceSinkReportingElement getSinkExitElement(
150+
Impl::Public::SinkElement sink, Impl::Private::SummaryComponent sc
151+
) {
152+
none()
153+
}
123154

124-
DataFlowCallable getSourceNodeEnclosingCallable(Input::SourceBase source) { none() }
155+
bindingset[e, sc]
156+
Node getSinkEntryNode(SourceSinkReportingElement e, Impl::Private::SummaryComponent sc) { none() }
157+
}
158+
159+
private import Impl::Private::Make2<Input2> as Impl2
125160

126-
Node getSourceNode(Input::SourceBase source, Impl::Private::SummaryComponentStack s) { none() }
161+
private module StepsInput implements Impl2::StepsInputSig {
162+
Impl2::SummaryNode getSummaryNode(Node n) { result = n.(FlowSummaryNode).getSummaryNode() }
127163

128-
Node getSinkNode(Input::SinkBase sink, Impl::Private::SummaryComponent sc) { none() }
164+
DataFlowCall getACall(Public::SummarizedCallable sc) { result.asCall().getStaticTarget() = sc }
129165
}
130166

131167
module SourceSinkInterpretationInput implements
@@ -252,8 +288,9 @@ module SourceSinkInterpretationInput implements
252288

253289
module Private {
254290
import Impl::Private
291+
import Impl2
255292

256-
module Steps = Impl::Private::Steps<StepsInput>;
293+
module Steps = Impl2::Steps<StepsInput>;
257294

258295
module External {
259296
import Impl::Private::External

swift/ql/lib/codeql/swift/dataflow/internal/TaintTrackingPrivate.qll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ private module Cached {
7676
model = ""
7777
or
7878
// flow through a flow summary (extension of `SummaryModelCsv`)
79-
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom,
80-
nodeTo.(FlowSummaryNode).getSummaryNode(), false, model)
79+
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, false, model)
8180
or
8281
any(AdditionalTaintStep a).step(nodeFrom, nodeTo) and model = "AdditionalTaintStep"
8382
}

0 commit comments

Comments
 (0)