Skip to content

Commit 1c3b8e2

Browse files
committed
Swift: Adjust to FlowSummaryImpl changes.
1 parent 4e531af commit 1c3b8e2

File tree

4 files changed

+52
-48
lines changed

4 files changed

+52
-48
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ newtype TDataFlowCall =
7575
TPropertySetterCall(PropertySetterCfgNode setter) or
7676
TPropertyObserverCall(PropertyObserverCfgNode observer) or
7777
TKeyPathCall(KeyPathApplicationExprCfgNode keyPathApplication) or
78-
TSummaryCall(FlowSummaryImpl::Public::SummarizedCallable c, Node receiver) {
78+
TSummaryCall(
79+
FlowSummaryImpl::Public::SummarizedCallable c, FlowSummaryImpl::Private::SummaryNode receiver
80+
) {
7981
FlowSummaryImpl::Private::summaryCallbackRange(c, receiver)
8082
}
8183

@@ -232,12 +234,12 @@ class PropertyObserverCall extends DataFlowCall, TPropertyObserverCall {
232234

233235
class SummaryCall extends DataFlowCall, TSummaryCall {
234236
private FlowSummaryImpl::Public::SummarizedCallable c;
235-
private Node receiver;
237+
private FlowSummaryImpl::Private::SummaryNode receiver;
236238

237239
SummaryCall() { this = TSummaryCall(c, receiver) }
238240

239241
/** Gets the data flow node that this call targets. */
240-
Node getReceiver() { result = receiver }
242+
FlowSummaryImpl::Private::SummaryNode getReceiver() { result = receiver }
241243

242244
override DataFlowCallable getEnclosingCallable() { result = TSummarizedCallable(c) }
243245

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

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,11 @@ private module Cached {
9090
TPatternNode(CfgNode n, Pattern p) { hasPatternNode(n, p) } or
9191
TSsaDefinitionNode(Ssa::Definition def) or
9292
TInoutReturnNode(ParamDecl param) { modifiableParam(param) } or
93-
TSummaryNode(FlowSummary::SummarizedCallable c, FlowSummaryImpl::Private::SummaryNodeState state) {
94-
FlowSummaryImpl::Private::summaryNodeRange(c, state)
95-
} or
93+
TFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn) or
9694
TSourceParameterNode(ParamDecl param) or
9795
TKeyPathParameterNode(EntryNode entry) { entry.getScope() instanceof KeyPathExpr } or
9896
TKeyPathReturnNode(ExitNode exit) { exit.getScope() instanceof KeyPathExpr } or
9997
TKeyPathComponentNode(KeyPathComponent component) or
100-
TSummaryParameterNode(FlowSummary::SummarizedCallable c, ParameterPosition pos) {
101-
FlowSummaryImpl::Private::summaryParameterNodeRange(c, pos)
102-
} or
10398
TExprPostUpdateNode(CfgNode n) {
10499
// Obviously, the base of setters needs a post-update node
105100
n = any(PropertySetterCfgNode setter).getBase()
@@ -223,7 +218,8 @@ private module Cached {
223218
nodeFrom.(KeyPathParameterNode).getComponent(0)
224219
or
225220
// flow through a flow summary (extension of `SummaryModelCsv`)
226-
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, true)
221+
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom.(FlowSummaryNode).getSummaryNode(),
222+
nodeTo.(FlowSummaryNode).getSummaryNode(), true)
227223
}
228224

229225
/**
@@ -318,22 +314,19 @@ private module ParameterNodes {
318314
override ParamDecl getParameter() { result = param }
319315
}
320316

321-
class SummaryParameterNode extends ParameterNodeImpl, TSummaryParameterNode {
322-
FlowSummary::SummarizedCallable sc;
323-
ParameterPosition pos;
317+
class SummaryParameterNode extends ParameterNodeImpl, FlowSummaryNode {
318+
SummaryParameterNode() {
319+
FlowSummaryImpl::Private::summaryParameterNode(this.getSummaryNode(), _)
320+
}
324321

325-
SummaryParameterNode() { this = TSummaryParameterNode(sc, pos) }
322+
private ParameterPosition getPosition() {
323+
FlowSummaryImpl::Private::summaryParameterNode(this.getSummaryNode(), result)
324+
}
326325

327326
override predicate isParameterOf(DataFlowCallable c, ParameterPosition p) {
328-
c.getUnderlyingCallable() = sc and
329-
p = pos
327+
c.getUnderlyingCallable() = this.getSummarizedCallable() and
328+
p = this.getPosition()
330329
}
331-
332-
override Location getLocationImpl() { result = sc.getLocation() }
333-
334-
override string toStringImpl() { result = "[summary param] " + pos + " in " + sc }
335-
336-
override DataFlowCallable getEnclosingCallable() { this.isParameterOf(result, _) }
337330
}
338331

339332
class KeyPathParameterNode extends ParameterNodeImpl, TKeyPathParameterNode {
@@ -362,17 +355,20 @@ private module ParameterNodes {
362355
import ParameterNodes
363356

364357
/** A data-flow node used to model flow summaries. */
365-
class SummaryNode extends NodeImpl, TSummaryNode {
366-
private FlowSummaryImpl::Public::SummarizedCallable c;
367-
private FlowSummaryImpl::Private::SummaryNodeState state;
358+
class FlowSummaryNode extends NodeImpl, TFlowSummaryNode {
359+
FlowSummaryImpl::Private::SummaryNode getSummaryNode() { this = TFlowSummaryNode(result) }
368360

369-
SummaryNode() { this = TSummaryNode(c, state) }
361+
FlowSummary::SummarizedCallable getSummarizedCallable() {
362+
result = this.getSummaryNode().getSummarizedCallable()
363+
}
370364

371-
override DataFlowCallable getEnclosingCallable() { result.asSummarizedCallable() = c }
365+
override DataFlowCallable getEnclosingCallable() {
366+
result.asSummarizedCallable() = this.getSummarizedCallable()
367+
}
372368

373-
override UnknownLocation getLocationImpl() { any() }
369+
override Location getLocationImpl() { result = this.getSummarizedCallable().getLocation() }
374370

375-
override string toStringImpl() { result = "[summary] " + state + " in " + c }
371+
override string toStringImpl() { result = this.getSummaryNode().toString() }
376372
}
377373

378374
/** A data-flow node that represents a call argument. */
@@ -448,11 +444,13 @@ private module ArgumentNodes {
448444
}
449445
}
450446

451-
class SummaryArgumentNode extends SummaryNode, ArgumentNode {
452-
SummaryArgumentNode() { FlowSummaryImpl::Private::summaryArgumentNode(_, this, _) }
447+
class SummaryArgumentNode extends FlowSummaryNode, ArgumentNode {
448+
SummaryArgumentNode() {
449+
FlowSummaryImpl::Private::summaryArgumentNode(_, this.getSummaryNode(), _)
450+
}
453451

454452
override predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
455-
FlowSummaryImpl::Private::summaryArgumentNode(call, this, pos)
453+
FlowSummaryImpl::Private::summaryArgumentNode(call, this.getSummaryNode(), pos)
456454
}
457455
}
458456

@@ -521,10 +519,10 @@ private module ReturnNodes {
521519
override string toStringImpl() { result = param.toString() + "[return]" }
522520
}
523521

524-
private class SummaryReturnNode extends SummaryNode, ReturnNode {
522+
private class SummaryReturnNode extends FlowSummaryNode, ReturnNode {
525523
private ReturnKind rk;
526524

527-
SummaryReturnNode() { FlowSummaryImpl::Private::summaryReturnNode(this, rk) }
525+
SummaryReturnNode() { FlowSummaryImpl::Private::summaryReturnNode(this.getSummaryNode(), rk) }
528526

529527
override ReturnKind getKind() { result = rk }
530528
}
@@ -577,11 +575,11 @@ private module OutNodes {
577575
}
578576
}
579577

580-
class SummaryOutNode extends OutNode, SummaryNode {
581-
SummaryOutNode() { FlowSummaryImpl::Private::summaryOutNode(_, this, _) }
578+
class SummaryOutNode extends OutNode, FlowSummaryNode {
579+
SummaryOutNode() { FlowSummaryImpl::Private::summaryOutNode(_, this.getSummaryNode(), _) }
582580

583581
override DataFlowCall getCall(ReturnKind kind) {
584-
FlowSummaryImpl::Private::summaryOutNode(result, this, kind)
582+
FlowSummaryImpl::Private::summaryOutNode(result, this.getSummaryNode(), kind)
585583
}
586584
}
587585

@@ -642,7 +640,8 @@ private module OutNodes {
642640
import OutNodes
643641

644642
predicate jumpStep(Node pred, Node succ) {
645-
FlowSummaryImpl::Private::Steps::summaryJumpStep(pred, succ)
643+
FlowSummaryImpl::Private::Steps::summaryJumpStep(pred.(FlowSummaryNode).getSummaryNode(),
644+
succ.(FlowSummaryNode).getSummaryNode())
646645
}
647646

648647
predicate storeStep(Node node1, ContentSet c, Node node2) {
@@ -692,7 +691,8 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
692691
init.isFailable()
693692
)
694693
or
695-
FlowSummaryImpl::Private::Steps::summaryStoreStep(node1, c, node2)
694+
FlowSummaryImpl::Private::Steps::summaryStoreStep(node1.(FlowSummaryNode).getSummaryNode(), c,
695+
node2.(FlowSummaryNode).getSummaryNode())
696696
}
697697

698698
predicate isLValue(Expr e) { any(AssignExpr assign).getDest() = e }
@@ -830,11 +830,14 @@ private module PostUpdateNodes {
830830
override DataFlowCallable getEnclosingCallable() { result = TDataFlowFunc(n.getScope()) }
831831
}
832832

833-
class SummaryPostUpdateNode extends SummaryNode, PostUpdateNodeImpl {
834-
SummaryPostUpdateNode() { FlowSummaryImpl::Private::summaryPostUpdateNode(this, _) }
833+
class SummaryPostUpdateNode extends FlowSummaryNode, PostUpdateNodeImpl {
834+
SummaryPostUpdateNode() {
835+
FlowSummaryImpl::Private::summaryPostUpdateNode(this.getSummaryNode(), _)
836+
}
835837

836838
override Node getPreUpdateNode() {
837-
FlowSummaryImpl::Private::summaryPostUpdateNode(this, result)
839+
FlowSummaryImpl::Private::summaryPostUpdateNode(this.getSummaryNode(),
840+
result.(FlowSummaryNode).getSummaryNode())
838841
}
839842
}
840843
}
@@ -883,7 +886,7 @@ predicate lambdaCall(DataFlowCall call, LambdaCallKind kind, Node receiver) {
883886
receiver.asExpr() = call.asCall().getExpr().(ApplyExpr).getFunction()
884887
or
885888
kind = TLambdaCallKind() and
886-
receiver = call.(SummaryCall).getReceiver()
889+
receiver.(FlowSummaryNode).getSummaryNode() = call.(SummaryCall).getReceiver()
887890
or
888891
kind = TLambdaCallKind() and
889892
receiver.asExpr() = call.asKeyPath().getExpr().(KeyPathApplicationExpr).getKeyPath()

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ DataFlowCallable inject(SummarizedCallable c) { result.getUnderlyingCallable() =
2020
/** Gets the parameter position of the instance parameter. */
2121
ArgumentPosition callbackSelfParameterPosition() { result instanceof ThisArgumentPosition }
2222

23-
/** Gets the synthesized summary data-flow node for the given values. */
24-
Node summaryNode(SummarizedCallable c, SummaryNodeState state) { result = TSummaryNode(c, state) }
25-
2623
/** Gets the synthesized data-flow call for `receiver`. */
27-
SummaryCall summaryDataFlowCall(Node receiver) { receiver = result.getReceiver() }
24+
SummaryCall summaryDataFlowCall(SummaryNode receiver) { receiver = result.getReceiver() }
2825

2926
/** Gets the type of content `c`. */
3027
DataFlowType getContentType(ContentSet c) { any() }

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ private module Cached {
6868
)
6969
or
7070
// flow through a flow summary (extension of `SummaryModelCsv`)
71-
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, false)
71+
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom
72+
.(DataFlowPrivate::FlowSummaryNode)
73+
.getSummaryNode(), nodeTo.(DataFlowPrivate::FlowSummaryNode).getSummaryNode(), false)
7274
or
7375
any(AdditionalTaintStep a).step(nodeFrom, nodeTo)
7476
}

0 commit comments

Comments
 (0)