Skip to content

Commit 4e531af

Browse files
committed
Ruby: Adjust to FlowSummaryImpl changes.
1 parent 1e3b960 commit 4e531af

File tree

5 files changed

+60
-64
lines changed

5 files changed

+60
-64
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ class DataFlowCall extends TDataFlowCall {
153153
*/
154154
class SummaryCall extends DataFlowCall, TSummaryCall {
155155
private FlowSummaryImpl::Public::SummarizedCallable c;
156-
private DataFlow::Node receiver;
156+
private FlowSummaryImpl::Private::SummaryNode receiver;
157157

158158
SummaryCall() { this = TSummaryCall(c, receiver) }
159159

160160
/** Gets the data flow node that this call targets. */
161-
DataFlow::Node getReceiver() { result = receiver }
161+
FlowSummaryImpl::Private::SummaryNode getReceiver() { result = receiver }
162162

163163
override DataFlowCallable getEnclosingCallable() { result.asLibraryCallable() = c }
164164

@@ -377,7 +377,9 @@ private module Cached {
377377
cached
378378
newtype TDataFlowCall =
379379
TNormalCall(CfgNodes::ExprNodes::CallCfgNode c) or
380-
TSummaryCall(FlowSummaryImpl::Public::SummarizedCallable c, DataFlow::Node receiver) {
380+
TSummaryCall(
381+
FlowSummaryImpl::Public::SummarizedCallable c, FlowSummaryImpl::Private::SummaryNode receiver
382+
) {
381383
FlowSummaryImpl::Private::summaryCallbackRange(c, receiver)
382384
}
383385

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

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -309,24 +309,16 @@ private module Cached {
309309
n = any(CfgNodes::ExprNodes::InstanceVariableAccessCfgNode v).getReceiver()
310310
)
311311
} or
312-
TSummaryNode(
313-
FlowSummaryImpl::Public::SummarizedCallable c,
314-
FlowSummaryImpl::Private::SummaryNodeState state
315-
) {
316-
FlowSummaryImpl::Private::summaryNodeRange(c, state)
317-
} or
318-
TSummaryParameterNode(FlowSummaryImpl::Public::SummarizedCallable c, ParameterPosition pos) {
319-
FlowSummaryImpl::Private::summaryParameterNodeRange(c, pos)
320-
} or
312+
TFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn) or
321313
TSynthHashSplatArgumentNode(CfgNodes::ExprNodes::CallCfgNode c) {
322314
exists(Argument arg | arg.isArgumentOf(c, any(ArgumentPosition pos | pos.isKeyword(_))))
323315
or
324316
c.getAnArgument() instanceof CfgNodes::ExprNodes::PairCfgNode
325317
}
326318

327-
class TParameterNode =
319+
class TSourceParameterNode =
328320
TNormalParameterNode or TBlockParameterNode or TSelfParameterNode or
329-
TSynthHashSplatParameterNode or TSummaryParameterNode;
321+
TSynthHashSplatParameterNode;
330322

331323
cached
332324
Location getLocation(NodeImpl n) { result = n.getLocationImpl() }
@@ -355,7 +347,8 @@ private module Cached {
355347
exprFrom = nodeFrom.(PostUpdateNode).getPreUpdateNode().asExpr()
356348
)
357349
or
358-
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, true)
350+
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom.(FlowSummaryNode).getSummaryNode(),
351+
nodeTo.(FlowSummaryNode).getSummaryNode(), true)
359352
}
360353

361354
/** This is the local flow predicate that is exposed. */
@@ -412,7 +405,9 @@ private module Cached {
412405

413406
cached
414407
predicate isLocalSourceNode(Node n) {
415-
n instanceof TParameterNode
408+
n instanceof TSourceParameterNode
409+
or
410+
n instanceof SummaryParameterNode
416411
or
417412
// Expressions that can't be reached from another entry definition or expression
418413
n instanceof ExprNode and
@@ -514,9 +509,7 @@ predicate nodeIsHidden(Node n) {
514509
or
515510
isDesugarNode(n.(ExprNode).getExprNode().getExpr())
516511
or
517-
n instanceof SummaryNode
518-
or
519-
n instanceof SummaryParameterNode
512+
n instanceof FlowSummaryNode
520513
or
521514
n instanceof SynthHashSplatParameterNode
522515
or
@@ -757,47 +750,43 @@ private module ParameterNodes {
757750
}
758751

759752
/** A parameter for a library callable with a flow summary. */
760-
class SummaryParameterNode extends ParameterNodeImpl, TSummaryParameterNode {
761-
private FlowSummaryImpl::Public::SummarizedCallable sc;
762-
private ParameterPosition pos_;
753+
class SummaryParameterNode extends ParameterNodeImpl, FlowSummaryNode {
754+
SummaryParameterNode() {
755+
FlowSummaryImpl::Private::summaryParameterNode(this.getSummaryNode(), _)
756+
}
763757

764-
SummaryParameterNode() { this = TSummaryParameterNode(sc, pos_) }
758+
private ParameterPosition getPosition() {
759+
FlowSummaryImpl::Private::summaryParameterNode(this.getSummaryNode(), result)
760+
}
765761

766762
override Parameter getParameter() { none() }
767763

768764
override predicate isParameterOf(DataFlowCallable c, ParameterPosition pos) {
769-
sc = c.asLibraryCallable() and pos = pos_
765+
this.getSummarizedCallable() = c.asLibraryCallable() and pos = this.getPosition()
770766
}
771-
772-
override CfgScope getCfgScope() { none() }
773-
774-
override DataFlowCallable getEnclosingCallable() { result.asLibraryCallable() = sc }
775-
776-
override EmptyLocation getLocationImpl() { any() }
777-
778-
override string toStringImpl() { result = "parameter " + pos_ + " of " + sc }
779767
}
780768
}
781769

782770
import ParameterNodes
783771

784772
/** A data-flow node used to model flow summaries. */
785-
class SummaryNode extends NodeImpl, TSummaryNode {
786-
FlowSummaryImpl::Public::SummarizedCallable c;
787-
FlowSummaryImpl::Private::SummaryNodeState state;
788-
789-
SummaryNode() { this = TSummaryNode(c, state) }
773+
class FlowSummaryNode extends NodeImpl, TFlowSummaryNode {
774+
FlowSummaryImpl::Private::SummaryNode getSummaryNode() { this = TFlowSummaryNode(result) }
790775

791776
/** Gets the summarized callable that this node belongs to. */
792-
FlowSummaryImpl::Public::SummarizedCallable getSummarizedCallable() { result = c }
777+
FlowSummaryImpl::Public::SummarizedCallable getSummarizedCallable() {
778+
result = this.getSummaryNode().getSummarizedCallable()
779+
}
793780

794781
override CfgScope getCfgScope() { none() }
795782

796-
override DataFlowCallable getEnclosingCallable() { result.asLibraryCallable() = c }
783+
override DataFlowCallable getEnclosingCallable() {
784+
result.asLibraryCallable() = this.getSummarizedCallable()
785+
}
797786

798787
override EmptyLocation getLocationImpl() { any() }
799788

800-
override string toStringImpl() { result = "[summary] " + state + " in " + c }
789+
override string toStringImpl() { result = this.getSummaryNode().toString() }
801790
}
802791

803792
/** A data-flow node that represents a call argument. */
@@ -857,15 +846,17 @@ private module ArgumentNodes {
857846
}
858847
}
859848

860-
private class SummaryArgumentNode extends SummaryNode, ArgumentNode {
861-
SummaryArgumentNode() { FlowSummaryImpl::Private::summaryArgumentNode(_, this, _) }
849+
private class SummaryArgumentNode extends FlowSummaryNode, ArgumentNode {
850+
SummaryArgumentNode() {
851+
FlowSummaryImpl::Private::summaryArgumentNode(_, this.getSummaryNode(), _)
852+
}
862853

863854
override predicate sourceArgumentOf(CfgNodes::ExprNodes::CallCfgNode call, ArgumentPosition pos) {
864855
none()
865856
}
866857

867858
override predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
868-
FlowSummaryImpl::Private::summaryArgumentNode(call, this, pos)
859+
FlowSummaryImpl::Private::summaryArgumentNode(call, this.getSummaryNode(), pos)
869860
}
870861
}
871862

@@ -1029,16 +1020,16 @@ private module ReturnNodes {
10291020
override ReturnKind getKind() { result instanceof NewReturnKind }
10301021
}
10311022

1032-
private class SummaryReturnNode extends SummaryNode, ReturnNode {
1023+
private class SummaryReturnNode extends FlowSummaryNode, ReturnNode {
10331024
private ReturnKind rk;
10341025

1035-
SummaryReturnNode() { FlowSummaryImpl::Private::summaryReturnNode(this, rk) }
1026+
SummaryReturnNode() { FlowSummaryImpl::Private::summaryReturnNode(this.getSummaryNode(), rk) }
10361027

10371028
override ReturnKind getKind() {
10381029
result = rk
10391030
or
10401031
exists(NewCall new |
1041-
TLibraryCallable(c) = viableLibraryCallable(new) and
1032+
TLibraryCallable(this.getSummarizedCallable()) = viableLibraryCallable(new) and
10421033
result instanceof NewReturnKind
10431034
)
10441035
}
@@ -1071,11 +1062,11 @@ private module OutNodes {
10711062
}
10721063
}
10731064

1074-
private class SummaryOutNode extends SummaryNode, OutNode {
1075-
SummaryOutNode() { FlowSummaryImpl::Private::summaryOutNode(_, this, _) }
1065+
private class SummaryOutNode extends FlowSummaryNode, OutNode {
1066+
SummaryOutNode() { FlowSummaryImpl::Private::summaryOutNode(_, this.getSummaryNode(), _) }
10761067

10771068
override DataFlowCall getCall(ReturnKind kind) {
1078-
FlowSummaryImpl::Private::summaryOutNode(result, this, kind)
1069+
FlowSummaryImpl::Private::summaryOutNode(result, this.getSummaryNode(), kind)
10791070
}
10801071
}
10811072
}
@@ -1091,7 +1082,8 @@ predicate jumpStep(Node pred, Node succ) {
10911082
or
10921083
succ.asExpr().getExpr().(ConstantReadAccess).getValue() = pred.asExpr().getExpr()
10931084
or
1094-
FlowSummaryImpl::Private::Steps::summaryJumpStep(pred, succ)
1085+
FlowSummaryImpl::Private::Steps::summaryJumpStep(pred.(FlowSummaryNode).getSummaryNode(),
1086+
succ.(FlowSummaryNode).getSummaryNode())
10951087
or
10961088
any(AdditionalJumpStep s).step(pred, succ)
10971089
}
@@ -1156,7 +1148,8 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
11561148
))
11571149
).getReceiver()
11581150
or
1159-
FlowSummaryImpl::Private::Steps::summaryStoreStep(node1, c, node2)
1151+
FlowSummaryImpl::Private::Steps::summaryStoreStep(node1.(FlowSummaryNode).getSummaryNode(), c,
1152+
node2.(FlowSummaryNode).getSummaryNode())
11601153
or
11611154
storeStepCommon(node1, c, node2)
11621155
}
@@ -1190,7 +1183,8 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
11901183
or
11911184
node2 = node1.(SynthHashSplatParameterNode).getAKeywordParameter(c)
11921185
or
1193-
FlowSummaryImpl::Private::Steps::summaryReadStep(node1, c, node2)
1186+
FlowSummaryImpl::Private::Steps::summaryReadStep(node1.(FlowSummaryNode).getSummaryNode(), c,
1187+
node2.(FlowSummaryNode).getSummaryNode())
11941188
}
11951189

11961190
/**
@@ -1199,7 +1193,7 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
11991193
* in `x.f = newValue`.
12001194
*/
12011195
predicate clearsContent(Node n, ContentSet c) {
1202-
FlowSummaryImpl::Private::Steps::summaryClearsContent(n, c)
1196+
FlowSummaryImpl::Private::Steps::summaryClearsContent(n.(FlowSummaryNode).getSummaryNode(), c)
12031197
or
12041198
// Filter out keyword arguments that are part of the method signature from
12051199
// the hash-splat parameter
@@ -1220,7 +1214,7 @@ predicate clearsContent(Node n, ContentSet c) {
12201214
* at node `n`.
12211215
*/
12221216
predicate expectsContent(Node n, ContentSet c) {
1223-
FlowSummaryImpl::Private::Steps::summaryExpectsContent(n, c)
1217+
FlowSummaryImpl::Private::Steps::summaryExpectsContent(n.(FlowSummaryNode).getSummaryNode(), c)
12241218
}
12251219

12261220
private newtype TDataFlowType =
@@ -1277,10 +1271,12 @@ private module PostUpdateNodes {
12771271
override string toStringImpl() { result = "[post] " + e.toString() }
12781272
}
12791273

1280-
private class SummaryPostUpdateNode extends SummaryNode, PostUpdateNodeImpl {
1281-
private Node pre;
1274+
private class SummaryPostUpdateNode extends FlowSummaryNode, PostUpdateNodeImpl {
1275+
private FlowSummaryNode pre;
12821276

1283-
SummaryPostUpdateNode() { FlowSummaryImpl::Private::summaryPostUpdateNode(this, pre) }
1277+
SummaryPostUpdateNode() {
1278+
FlowSummaryImpl::Private::summaryPostUpdateNode(this.getSummaryNode(), pre.getSummaryNode())
1279+
}
12841280

12851281
override Node getPreUpdateNode() { result = pre }
12861282
}
@@ -1355,7 +1351,7 @@ predicate lambdaSourceCall(CfgNodes::ExprNodes::CallCfgNode call, LambdaCallKind
13551351
predicate lambdaCall(DataFlowCall call, LambdaCallKind kind, Node receiver) {
13561352
lambdaSourceCall(call.asCall(), kind, receiver)
13571353
or
1358-
receiver = call.(SummaryCall).getReceiver() and
1354+
receiver.(FlowSummaryNode).getSummaryNode() = call.(SummaryCall).getReceiver() and
13591355
if receiver.(ParameterNodeImpl).isParameterOf(_, any(ParameterPosition pos | pos.isBlock()))
13601356
then kind = TYieldCallKind()
13611357
else kind = TLambdaCallKind()

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPublic.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class ExprNode extends Node, TExprNode {
191191
* The value of a parameter at function entry, viewed as a node in a data
192192
* flow graph.
193193
*/
194-
class ParameterNode extends LocalSourceNode, TParameterNode instanceof ParameterNodeImpl {
194+
class ParameterNode extends LocalSourceNode instanceof ParameterNodeImpl {
195195
/** Gets the parameter corresponding to this node, if any. */
196196
final Parameter getParameter() { result = super.getParameter() }
197197

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ DataFlowCallable inject(SummarizedCallable c) { result.asLibraryCallable() = c }
1818
/** Gets the parameter position representing a callback itself, if any. */
1919
ArgumentPosition callbackSelfParameterPosition() { none() } // disables implicit summary flow to `self` for callbacks
2020

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

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ private module Cached {
9696
)
9797
)
9898
or
99-
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, false)
99+
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom.(FlowSummaryNode).getSummaryNode(),
100+
nodeTo.(FlowSummaryNode).getSummaryNode(), false)
100101
or
101102
any(FlowSteps::AdditionalTaintStep s).step(nodeFrom, nodeTo)
102103
or

0 commit comments

Comments
 (0)