Skip to content

Commit faaa558

Browse files
committed
Python: Use FlowSummaryImpl from dataflow pack
1 parent a2093c9 commit faaa558

File tree

19 files changed

+249
-2088
lines changed

19 files changed

+249
-2088
lines changed

config/identical-files.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"DataFlow Java/C#/Go/Ruby/Python/Swift Flow Summaries": [
5757
"java/ql/lib/semmle/code/java/dataflow/internal/FlowSummaryImpl.qll",
5858
"go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll",
59-
"python/ql/lib/semmle/python/dataflow/new/internal/FlowSummaryImpl.qll",
6059
"swift/ql/lib/codeql/swift/dataflow/internal/FlowSummaryImpl.qll"
6160
],
6261
"SsaReadPosition Java/C#": [
@@ -467,7 +466,6 @@
467466
"AccessPathSyntax": [
468467
"go/ql/lib/semmle/go/dataflow/internal/AccessPathSyntax.qll",
469468
"java/ql/lib/semmle/code/java/dataflow/internal/AccessPathSyntax.qll",
470-
"python/ql/lib/semmle/python/dataflow/new/internal/AccessPathSyntax.qll",
471469
"swift/ql/lib/codeql/swift/dataflow/internal/AccessPathSyntax.qll"
472470
],
473471
"IncompleteUrlSubstringSanitization": [

python/ql/lib/semmle/python/dataflow/new/FlowSummary.qll

Lines changed: 10 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,83 +13,29 @@ private module Summaries {
1313
private import semmle.python.Frameworks
1414
}
1515

16-
class SummaryComponent = Impl::Public::SummaryComponent;
16+
deprecated class SummaryComponent = Impl::Private::SummaryComponent;
1717

1818
/** Provides predicates for constructing summary components. */
19-
module SummaryComponent {
20-
private import Impl::Public::SummaryComponent as SC
19+
deprecated module SummaryComponent = Impl::Private::SummaryComponent;
2120

22-
predicate parameter = SC::parameter/1;
21+
deprecated class SummaryComponentStack = Impl::Private::SummaryComponentStack;
2322

24-
predicate argument = SC::argument/1;
25-
26-
predicate content = SC::content/1;
27-
28-
/** Gets a summary component that represents a list element. */
29-
SummaryComponent listElement() { result = content(any(ListElementContent c)) }
30-
31-
/** Gets a summary component that represents a set element. */
32-
SummaryComponent setElement() { result = content(any(SetElementContent c)) }
33-
34-
/** Gets a summary component that represents a tuple element. */
35-
SummaryComponent tupleElement(int index) {
36-
exists(TupleElementContent c | c.getIndex() = index and result = content(c))
37-
}
38-
39-
/** Gets a summary component that represents a dictionary element. */
40-
SummaryComponent dictionaryElement(string key) {
41-
exists(DictionaryElementContent c | c.getKey() = key and result = content(c))
42-
}
43-
44-
/** Gets a summary component that represents a dictionary element at any key. */
45-
SummaryComponent dictionaryElementAny() { result = content(any(DictionaryElementAnyContent c)) }
46-
47-
/** Gets a summary component that represents an attribute element. */
48-
SummaryComponent attribute(string attr) {
49-
exists(AttributeContent c | c.getAttribute() = attr and result = content(c))
50-
}
51-
52-
/** Gets a summary component that represents the return value of a call. */
53-
SummaryComponent return() { result = SC::return(any(ReturnKind rk)) }
54-
}
55-
56-
class SummaryComponentStack = Impl::Public::SummaryComponentStack;
57-
58-
/** Provides predicates for constructing stacks of summary components. */
59-
module SummaryComponentStack {
60-
private import Impl::Public::SummaryComponentStack as SCS
61-
62-
predicate singleton = SCS::singleton/1;
63-
64-
predicate push = SCS::push/2;
65-
66-
predicate argument = SCS::argument/1;
67-
68-
/** Gets a singleton stack representing the return value of a call. */
69-
SummaryComponentStack return() { result = singleton(SummaryComponent::return()) }
70-
}
23+
deprecated module SummaryComponentStack = Impl::Private::SummaryComponentStack;
7124

7225
/** A callable with a flow summary, identified by a unique string. */
7326
abstract class SummarizedCallable extends LibraryCallable, Impl::Public::SummarizedCallable {
7427
bindingset[this]
7528
SummarizedCallable() { any() }
7629

7730
/**
78-
* Same as
79-
*
80-
* ```ql
81-
* propagatesFlow(
82-
* SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
83-
* )
84-
* ```
85-
*
86-
* but uses an external (string) representation of the input and output stacks.
31+
* DEPRECATED: Use `propagatesFlow` instead.
8732
*/
88-
pragma[nomagic]
89-
predicate propagatesFlowExt(string input, string output, boolean preservesValue) { none() }
33+
deprecated predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
34+
this.propagatesFlow(input, output, preservesValue)
35+
}
9036
}
9137

92-
class RequiredSummaryComponentStack = Impl::Public::RequiredSummaryComponentStack;
38+
deprecated class RequiredSummaryComponentStack = Impl::Private::RequiredSummaryComponentStack;
9339

9440
private class SummarizedCallableFromModel extends SummarizedCallable {
9541
string type;
@@ -109,7 +55,7 @@ private class SummarizedCallableFromModel extends SummarizedCallable {
10955
)
11056
}
11157

112-
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
58+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
11359
exists(string kind | ModelOutput::relevantSummaryModel(type, path, input, output, kind) |
11460
kind = "value" and
11561
preservesValue = true

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

Lines changed: 0 additions & 182 deletions
This file was deleted.

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ private import python
3636
private import DataFlowPublic
3737
private import DataFlowPrivate
3838
private import FlowSummaryImpl as FlowSummaryImpl
39-
private import FlowSummaryImplSpecific as FlowSummaryImplSpecific
4039
private import semmle.python.internal.CachedStages
4140
private import semmle.python.dataflow.new.internal.TypeTracker::CallGraphConstruction as CallGraphConstruction
4241

@@ -49,13 +48,13 @@ newtype TParameterPosition =
4948
// since synthetic parameters are made for a synthetic summary callable, based on
5049
// what Argument positions they have flow for, we need to make sure we have such
5150
// parameter positions available.
52-
FlowSummaryImplSpecific::ParsePositions::isParsedPositionalArgumentPosition(_, index)
51+
FlowSummaryImpl::ParsePositions::isParsedPositionalArgumentPosition(_, index)
5352
} or
5453
TKeywordParameterPosition(string name) {
5554
name = any(Parameter p).getName()
5655
or
5756
// see comment for TPositionalParameterPosition
58-
FlowSummaryImplSpecific::ParsePositions::isParsedKeywordArgumentPosition(_, name)
57+
FlowSummaryImpl::ParsePositions::isParsedKeywordArgumentPosition(_, name)
5958
} or
6059
TStarArgsParameterPosition(int index) {
6160
// since `.getPosition` does not work for `*args`, we need *args parameter positions
@@ -136,13 +135,13 @@ newtype TArgumentPosition =
136135
// since synthetic calls within a summarized callable could use a unique argument
137136
// position, we need to ensure we make these available (these are specified as
138137
// parameters in the flow-summary spec)
139-
FlowSummaryImplSpecific::ParsePositions::isParsedPositionalParameterPosition(_, index)
138+
FlowSummaryImpl::ParsePositions::isParsedPositionalParameterPosition(_, index)
140139
} or
141140
TKeywordArgumentPosition(string name) {
142141
exists(any(CallNode c).getArgByName(name))
143142
or
144143
// see comment for TPositionalArgumentPosition
145-
FlowSummaryImplSpecific::ParsePositions::isParsedKeywordParameterPosition(_, name)
144+
FlowSummaryImpl::ParsePositions::isParsedKeywordParameterPosition(_, name)
146145
} or
147146
TStarArgsArgumentPosition(int index) {
148147
exists(Call c | c.getPositionalArg(index) instanceof Starred)
@@ -1559,12 +1558,15 @@ private class SummaryReturnNode extends FlowSummaryNode, ReturnNode {
15591558
}
15601559

15611560
private class SummaryArgumentNode extends FlowSummaryNode, ArgumentNode {
1561+
private SummaryCall call_;
1562+
private ArgumentPosition pos_;
1563+
15621564
SummaryArgumentNode() {
1563-
FlowSummaryImpl::Private::summaryArgumentNode(_, this.getSummaryNode(), _)
1565+
FlowSummaryImpl::Private::summaryArgumentNode(call_.getReceiver(), this.getSummaryNode(), _)
15641566
}
15651567

15661568
override predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
1567-
FlowSummaryImpl::Private::summaryArgumentNode(call, this.getSummaryNode(), pos)
1569+
call = call_ and pos = pos_
15681570
}
15691571
}
15701572

@@ -1662,10 +1664,16 @@ private module OutNodes {
16621664
}
16631665

16641666
private class SummaryOutNode extends FlowSummaryNode, OutNode {
1665-
SummaryOutNode() { FlowSummaryImpl::Private::summaryOutNode(_, this.getSummaryNode(), _) }
1667+
private SummaryCall call;
1668+
private ReturnKind kind_;
1669+
1670+
SummaryOutNode() {
1671+
FlowSummaryImpl::Private::summaryOutNode(call.getReceiver(), this.getSummaryNode(), kind_)
1672+
}
16661673

16671674
override DataFlowCall getCall(ReturnKind kind) {
1668-
FlowSummaryImpl::Private::summaryOutNode(result, this.getSummaryNode(), kind)
1675+
result = call and
1676+
kind = kind_
16691677
}
16701678
}
16711679
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,10 @@ predicate additionalLambdaFlowStep(Node nodeFrom, Node nodeTo, boolean preserves
10281028
* by default as a heuristic.
10291029
*/
10301030
predicate allowParameterReturnInSelf(ParameterNode p) {
1031-
FlowSummaryImpl::Private::summaryAllowParameterReturnInSelf(p)
1031+
exists(DataFlowCallable c, ParameterPosition pos |
1032+
p.(ParameterNodeImpl).isParameterOf(c, pos) and
1033+
FlowSummaryImpl::Private::summaryAllowParameterReturnInSelf(c.asLibraryCallable(), pos)
1034+
)
10321035
}
10331036

10341037
/** An approximated `Content`. */

0 commit comments

Comments
 (0)