Skip to content

Commit 1e3b960

Browse files
committed
Python: Adjust to FlowSummaryImpl changes.
1 parent e6e4cef commit 1e3b960

File tree

4 files changed

+52
-62
lines changed

4 files changed

+52
-62
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,9 @@ newtype TDataFlowCall =
13161316
TNormalCall(CallNode call, Function target, CallType type) { resolveCall(call, target, type) } or
13171317
TPotentialLibraryCall(CallNode call) or
13181318
/** A synthesized call inside a summarized callable */
1319-
TSummaryCall(FlowSummaryImpl::Public::SummarizedCallable c, Node receiver) {
1319+
TSummaryCall(
1320+
FlowSummaryImpl::Public::SummarizedCallable c, FlowSummaryImpl::Private::SummaryNode receiver
1321+
) {
13201322
FlowSummaryImpl::Private::summaryCallbackRange(c, receiver)
13211323
}
13221324

@@ -1448,12 +1450,12 @@ class PotentialLibraryCall extends ExtractedDataFlowCall, TPotentialLibraryCall
14481450
*/
14491451
class SummaryCall extends DataFlowCall, TSummaryCall {
14501452
private FlowSummaryImpl::Public::SummarizedCallable c;
1451-
private Node receiver;
1453+
private FlowSummaryImpl::Private::SummaryNode receiver;
14521454

14531455
SummaryCall() { this = TSummaryCall(c, receiver) }
14541456

14551457
/** Gets the data flow node that this call targets. */
1456-
Node getReceiver() { result = receiver }
1458+
FlowSummaryImpl::Private::SummaryNode getReceiver() { result = receiver }
14571459

14581460
override DataFlowCallable getEnclosingCallable() { result.asLibraryCallable() = c }
14591461

@@ -1486,44 +1488,35 @@ abstract class ParameterNodeImpl extends Node {
14861488
}
14871489

14881490
/** A parameter for a library callable with a flow summary. */
1489-
class SummaryParameterNode extends ParameterNodeImpl, TSummaryParameterNode {
1490-
private FlowSummaryImpl::Public::SummarizedCallable sc;
1491-
private ParameterPosition pos;
1491+
class SummaryParameterNode extends ParameterNodeImpl, FlowSummaryNode {
1492+
SummaryParameterNode() {
1493+
FlowSummaryImpl::Private::summaryParameterNode(this.getSummaryNode(), _)
1494+
}
14921495

1493-
SummaryParameterNode() { this = TSummaryParameterNode(sc, pos) }
1496+
private ParameterPosition getPosition() {
1497+
FlowSummaryImpl::Private::summaryParameterNode(this.getSummaryNode(), result)
1498+
}
14941499

14951500
override Parameter getParameter() { none() }
14961501

14971502
override predicate isParameterOf(DataFlowCallable c, ParameterPosition ppos) {
1498-
sc = c.asLibraryCallable() and ppos = pos
1499-
}
1500-
1501-
override DataFlowCallable getEnclosingCallable() { result.asLibraryCallable() = sc }
1502-
1503-
override string toString() { result = "parameter " + pos + " of " + sc }
1504-
1505-
// Hack to return "empty location"
1506-
override predicate hasLocationInfo(
1507-
string file, int startline, int startcolumn, int endline, int endcolumn
1508-
) {
1509-
file = "" and
1510-
startline = 0 and
1511-
startcolumn = 0 and
1512-
endline = 0 and
1513-
endcolumn = 0
1503+
this.getSummarizedCallable() = c.asLibraryCallable() and ppos = this.getPosition()
15141504
}
15151505
}
15161506

15171507
/** A data-flow node used to model flow summaries. */
1518-
class SummaryNode extends Node, TSummaryNode {
1519-
private FlowSummaryImpl::Public::SummarizedCallable c;
1520-
private FlowSummaryImpl::Private::SummaryNodeState state;
1508+
class FlowSummaryNode extends Node, TFlowSummaryNode {
1509+
FlowSummaryImpl::Private::SummaryNode getSummaryNode() { this = TFlowSummaryNode(result) }
15211510

1522-
SummaryNode() { this = TSummaryNode(c, state) }
1511+
FlowSummaryImpl::Public::SummarizedCallable getSummarizedCallable() {
1512+
result = this.getSummaryNode().getSummarizedCallable()
1513+
}
15231514

1524-
override DataFlowCallable getEnclosingCallable() { result.asLibraryCallable() = c }
1515+
override DataFlowCallable getEnclosingCallable() {
1516+
result.asLibraryCallable() = this.getSummarizedCallable()
1517+
}
15251518

1526-
override string toString() { result = "[summary] " + state + " in " + c }
1519+
override string toString() { result = this.getSummaryNode().toString() }
15271520

15281521
// Hack to return "empty location"
15291522
override predicate hasLocationInfo(
@@ -1537,26 +1530,30 @@ class SummaryNode extends Node, TSummaryNode {
15371530
}
15381531
}
15391532

1540-
private class SummaryReturnNode extends SummaryNode, ReturnNode {
1533+
private class SummaryReturnNode extends FlowSummaryNode, ReturnNode {
15411534
private ReturnKind rk;
15421535

1543-
SummaryReturnNode() { FlowSummaryImpl::Private::summaryReturnNode(this, rk) }
1536+
SummaryReturnNode() { FlowSummaryImpl::Private::summaryReturnNode(this.getSummaryNode(), rk) }
15441537

15451538
override ReturnKind getKind() { result = rk }
15461539
}
15471540

1548-
private class SummaryArgumentNode extends SummaryNode, ArgumentNode {
1549-
SummaryArgumentNode() { FlowSummaryImpl::Private::summaryArgumentNode(_, this, _) }
1541+
private class SummaryArgumentNode extends FlowSummaryNode, ArgumentNode {
1542+
SummaryArgumentNode() {
1543+
FlowSummaryImpl::Private::summaryArgumentNode(_, this.getSummaryNode(), _)
1544+
}
15501545

15511546
override predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
1552-
FlowSummaryImpl::Private::summaryArgumentNode(call, this, pos)
1547+
FlowSummaryImpl::Private::summaryArgumentNode(call, this.getSummaryNode(), pos)
15531548
}
15541549
}
15551550

1556-
private class SummaryPostUpdateNode extends SummaryNode, PostUpdateNodeImpl {
1557-
private Node pre;
1551+
private class SummaryPostUpdateNode extends FlowSummaryNode, PostUpdateNodeImpl {
1552+
private FlowSummaryNode pre;
15581553

1559-
SummaryPostUpdateNode() { FlowSummaryImpl::Private::summaryPostUpdateNode(this, pre) }
1554+
SummaryPostUpdateNode() {
1555+
FlowSummaryImpl::Private::summaryPostUpdateNode(this.getSummaryNode(), pre.getSummaryNode())
1556+
}
15601557

15611558
override Node getPreUpdateNode() { result = pre }
15621559
}
@@ -1625,11 +1622,11 @@ private module OutNodes {
16251622
}
16261623
}
16271624

1628-
private class SummaryOutNode extends SummaryNode, OutNode {
1629-
SummaryOutNode() { FlowSummaryImpl::Private::summaryOutNode(_, this, _) }
1625+
private class SummaryOutNode extends FlowSummaryNode, OutNode {
1626+
SummaryOutNode() { FlowSummaryImpl::Private::summaryOutNode(_, this.getSummaryNode(), _) }
16301627

16311628
override DataFlowCall getCall(ReturnKind kind) {
1632-
FlowSummaryImpl::Private::summaryOutNode(result, this, kind)
1629+
FlowSummaryImpl::Private::summaryOutNode(result, this.getSummaryNode(), kind)
16331630
}
16341631
}
16351632
}

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPrivate.qll

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,14 +441,16 @@ predicate importTimeSummaryFlowStep(Node nodeFrom, Node nodeTo) {
441441
// This will miss statements inside functions called from the top level.
442442
isTopLevel(nodeFrom) and
443443
isTopLevel(nodeTo) and
444-
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, true)
444+
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom.(FlowSummaryNode).getSummaryNode(),
445+
nodeTo.(FlowSummaryNode).getSummaryNode(), true)
445446
}
446447

447448
predicate runtimeSummaryFlowStep(Node nodeFrom, Node nodeTo) {
448449
// Anything not at the top level can be executed at runtime.
449450
not isTopLevel(nodeFrom) and
450451
not isTopLevel(nodeTo) and
451-
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, true)
452+
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom.(FlowSummaryNode).getSummaryNode(),
453+
nodeTo.(FlowSummaryNode).getSummaryNode(), true)
452454
}
453455

454456
/** `ModuleVariable`s are accessed via jump steps at runtime. */
@@ -529,7 +531,8 @@ predicate jumpStep(Node nodeFrom, Node nodeTo) {
529531
or
530532
jumpStepNotSharedWithTypeTracker(nodeFrom, nodeTo)
531533
or
532-
FlowSummaryImpl::Private::Steps::summaryJumpStep(nodeFrom, nodeTo)
534+
FlowSummaryImpl::Private::Steps::summaryJumpStep(nodeFrom.(FlowSummaryNode).getSummaryNode(),
535+
nodeTo.(FlowSummaryNode).getSummaryNode())
533536
}
534537

535538
/**
@@ -602,7 +605,8 @@ predicate storeStep(Node nodeFrom, Content c, Node nodeTo) {
602605
or
603606
any(Orm::AdditionalOrmSteps es).storeStep(nodeFrom, c, nodeTo)
604607
or
605-
FlowSummaryImpl::Private::Steps::summaryStoreStep(nodeFrom, c, nodeTo)
608+
FlowSummaryImpl::Private::Steps::summaryStoreStep(nodeFrom.(FlowSummaryNode).getSummaryNode(), c,
609+
nodeTo.(FlowSummaryNode).getSummaryNode())
606610
or
607611
synthStarArgsElementParameterNodeStoreStep(nodeFrom, c, nodeTo)
608612
or
@@ -806,7 +810,8 @@ predicate readStep(Node nodeFrom, Content c, Node nodeTo) {
806810
or
807811
attributeReadStep(nodeFrom, c, nodeTo)
808812
or
809-
FlowSummaryImpl::Private::Steps::summaryReadStep(nodeFrom, c, nodeTo)
813+
FlowSummaryImpl::Private::Steps::summaryReadStep(nodeFrom.(FlowSummaryNode).getSummaryNode(), c,
814+
nodeTo.(FlowSummaryNode).getSummaryNode())
810815
or
811816
synthDictSplatParameterNodeReadStep(nodeFrom, c, nodeTo)
812817
}
@@ -921,7 +926,7 @@ predicate clearsContent(Node n, Content c) {
921926
or
922927
dictClearStep(n, c)
923928
or
924-
FlowSummaryImpl::Private::Steps::summaryClearsContent(n, c)
929+
FlowSummaryImpl::Private::Steps::summaryClearsContent(n.(FlowSummaryNode).getSummaryNode(), c)
925930
or
926931
dictSplatParameterNodeClearStep(n, c)
927932
}
@@ -978,9 +983,7 @@ predicate forceHighPrecision(Content c) { none() }
978983
predicate nodeIsHidden(Node n) {
979984
n instanceof ModuleVariableNode
980985
or
981-
n instanceof SummaryNode
982-
or
983-
n instanceof SummaryParameterNode
986+
n instanceof FlowSummaryNode
984987
or
985988
n instanceof SynthStarArgsElementParameterNode
986989
or
@@ -1007,7 +1010,7 @@ predicate lambdaCreation(Node creation, LambdaCallKind kind, DataFlowCallable c)
10071010

10081011
/** Holds if `call` is a lambda call of kind `kind` where `receiver` is the lambda expression. */
10091012
predicate lambdaCall(DataFlowCall call, LambdaCallKind kind, Node receiver) {
1010-
receiver = call.(SummaryCall).getReceiver() and
1013+
receiver.(FlowSummaryNode).getSummaryNode() = call.(SummaryCall).getReceiver() and
10111014
exists(kind)
10121015
}
10131016

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPublic.qll

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,7 @@ newtype TNode =
105105
// So for now we live with having these synthetic ORM nodes for _all_ classes, which
106106
// is a bit wasteful, but we don't think it will hurt too much.
107107
TSyntheticOrmModelNode(Class cls) or
108-
TSummaryNode(
109-
FlowSummaryImpl::Public::SummarizedCallable c, FlowSummaryImpl::Private::SummaryNodeState state
110-
) {
111-
FlowSummaryImpl::Private::summaryNodeRange(c, state)
112-
} or
113-
TSummaryParameterNode(FlowSummaryImpl::Public::SummarizedCallable c, ParameterPosition pos) {
114-
FlowSummaryImpl::Private::summaryParameterNodeRange(c, pos)
115-
} or
108+
TFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn) or
116109
/** A synthetic node to capture positional arguments that are passed to a `*args` parameter. */
117110
TSynthStarArgsElementParameterNode(DataFlowCallable callable) {
118111
exists(ParameterPosition ppos | ppos.isStarArgs(_) | exists(callable.getParameter(ppos)))

python/ql/lib/semmle/python/dataflow/new/internal/FlowSummaryImplSpecific.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@ DataFlowCallable inject(SummarizedCallable c) { result.asLibraryCallable() = c }
4747
/** Gets the parameter position of the instance parameter. */
4848
ArgumentPosition callbackSelfParameterPosition() { none() } // disables implicit summary flow to `this` for callbacks
4949

50-
/** Gets the synthesized summary data-flow node for the given values. */
51-
Node summaryNode(SummarizedCallable c, SummaryNodeState state) { result = TSummaryNode(c, state) }
52-
5350
/** Gets the synthesized data-flow call for `receiver`. */
54-
SummaryCall summaryDataFlowCall(Node receiver) { receiver = result.getReceiver() }
51+
SummaryCall summaryDataFlowCall(SummaryNode receiver) { receiver = result.getReceiver() }
5552

5653
/** Gets the type of content `c`. */
5754
DataFlowType getContentType(Content c) { any() }

0 commit comments

Comments
 (0)