Skip to content

Commit f263799

Browse files
committed
Python: Adapt to FlowSummaryImpl changes
1 parent 030ddb4 commit f263799

4 files changed

Lines changed: 61 additions & 31 deletions

File tree

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,21 +1711,12 @@ class FlowSummaryNode extends Node, TFlowSummaryNode {
17111711
}
17121712

17131713
override DataFlowCallable getEnclosingCallable() {
1714-
result.asLibraryCallable() = this.getSummarizedCallable()
1714+
result = this.getSummaryNode().getEnclosingCallable()
17151715
}
17161716

17171717
override string toString() { result = this.getSummaryNode().toString() }
17181718

1719-
// Hack to return "empty location"
1720-
deprecated override predicate hasLocationInfo(
1721-
string file, int startline, int startcolumn, int endline, int endcolumn
1722-
) {
1723-
file = "" and
1724-
startline = 0 and
1725-
startcolumn = 0 and
1726-
endline = 0 and
1727-
endcolumn = 0
1728-
}
1719+
override Location getLocation() { result = this.getSummaryNode().getLocation() }
17291720
}
17301721

17311722
private class SummaryReturnNode extends FlowSummaryNode, ReturnNode {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,7 @@ predicate simpleLocalFlowStepForTypetracking(Node nodeFrom, Node nodeTo) {
529529
}
530530

531531
private predicate summaryLocalStep(Node nodeFrom, Node nodeTo, string model) {
532-
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom,
533-
nodeTo.(FlowSummaryNode).getSummaryNode(), true, model)
532+
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, true, model)
534533
}
535534

536535
predicate variableCaptureLocalFlowStep(Node nodeFrom, Node nodeTo) {
@@ -697,8 +696,7 @@ predicate jumpStep(Node nodeFrom, Node nodeTo) {
697696
or
698697
jumpStepNotSharedWithTypeTracker(nodeFrom, nodeTo)
699698
or
700-
FlowSummaryImpl::Private::Steps::summaryJumpStep(nodeFrom.(FlowSummaryNode).getSummaryNode(),
701-
nodeTo.(FlowSummaryNode).getSummaryNode())
699+
FlowSummaryImpl::Private::Steps::summaryJumpStep(nodeFrom, nodeTo)
702700
}
703701

704702
/**

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

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,27 @@ private import DataFlowImplSpecific::Public
1414
module Input implements InputSig<Location, DataFlowImplSpecific::PythonDataFlow> {
1515
private import codeql.util.Void
1616

17-
class SummarizedCallableBase = string;
17+
class SummarizedCallableBase extends string {
18+
bindingset[this]
19+
SummarizedCallableBase() { exists(this) }
1820

19-
class SourceBase = Void;
21+
Location getLocation() { none() }
22+
}
23+
24+
class SourceBase extends Void {
25+
Location getLocation() { none() }
26+
}
2027

21-
class SinkBase = Void;
28+
class SinkBase = SourceBase;
2229

23-
class FlowSummaryCallBase = Void;
30+
class FlowSummaryCallBase = SourceBase;
2431

2532
predicate callableFromSource(SummarizedCallableBase c) { none() }
2633

34+
DataFlowCallable getSummarizedCallableAsDataFlowCallable(SummarizedCallableBase c) {
35+
result.asLibraryCallable() = c
36+
}
37+
2738
ArgumentPosition callbackSelfParameterPosition() { result.isLambdaSelf() }
2839

2940
ReturnKind getStandardReturnValueKind() { any() }
@@ -112,11 +123,47 @@ module Input implements InputSig<Location, DataFlowImplSpecific::PythonDataFlow>
112123

113124
private import Make<Location, DataFlowImplSpecific::PythonDataFlow, Input> as Impl
114125

115-
private module StepsInput implements Impl::Private::StepsInputSig {
116-
Impl::Private::SummaryNode getSummaryNode(Node n) {
117-
result = n.(FlowSummaryNode).getSummaryNode()
126+
private module Input2 implements Impl::Private::InputSig2 {
127+
private import codeql.util.Void
128+
129+
class SourceSinkReportingElement extends Void {
130+
Location getLocation() { none() }
131+
132+
DataFlowCallable getEnclosingCallable() { none() }
133+
}
134+
135+
SourceSinkReportingElement getSourceEntryElement(
136+
Impl::Public::SourceElement source, Impl::Private::SummaryComponent sc
137+
) {
138+
none()
139+
}
140+
141+
SourceSinkReportingElement getNextElement(
142+
SourceSinkReportingElement prev, Impl::Private::SummaryComponent sc
143+
) {
144+
none()
118145
}
119146

147+
bindingset[e, sc]
148+
Node getSourceExitNode(SourceSinkReportingElement e, Impl::Private::SummaryComponent sc) {
149+
none()
150+
}
151+
152+
SourceSinkReportingElement getSinkExitElement(
153+
Impl::Public::SinkElement sink, Impl::Private::SummaryComponent sc
154+
) {
155+
none()
156+
}
157+
158+
bindingset[e, sc]
159+
Node getSinkEntryNode(SourceSinkReportingElement e, Impl::Private::SummaryComponent sc) { none() }
160+
}
161+
162+
private import Impl::Private::Make2<Input2> as Impl2
163+
164+
private module StepsInput implements Impl2::StepsInputSig {
165+
Impl2::SummaryNode getSummaryNode(Node n) { result = n.(FlowSummaryNode).getSummaryNode() }
166+
120167
overlay[global]
121168
DataFlowCall getACall(Public::SummarizedCallable sc) {
122169
result =
@@ -125,18 +172,13 @@ private module StepsInput implements Impl::Private::StepsInputSig {
125172
sc.(LibraryCallable).getACallSimple().asCfgNode()
126173
])
127174
}
128-
129-
DataFlowCallable getSourceNodeEnclosingCallable(Input::SourceBase source) { none() }
130-
131-
Node getSourceNode(Input::SourceBase source, Impl::Private::SummaryComponentStack s) { none() }
132-
133-
Node getSinkNode(Input::SinkBase sink, Impl::Private::SummaryComponent sc) { none() }
134175
}
135176

136177
module Private {
137178
import Impl::Private
179+
import Impl2
138180

139-
module Steps = Impl::Private::Steps<StepsInput>;
181+
module Steps = Impl2::Steps<StepsInput>;
140182

141183
/**
142184
* Provides predicates for constructing summary components.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ private module Cached {
8080
) and
8181
model = ""
8282
or
83-
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom,
84-
nodeTo.(DataFlowPrivate::FlowSummaryNode).getSummaryNode(), false, model)
83+
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, false, model)
8584
}
8685
}
8786

0 commit comments

Comments
 (0)