Skip to content

Commit 86454e7

Browse files
committed
Python: Adapt to changes in FlowSummaryImpl
1 parent f6d1621 commit 86454e7

File tree

8 files changed

+101
-87
lines changed

8 files changed

+101
-87
lines changed

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

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,39 @@ deprecated class SummaryComponentStack = Impl::Private::SummaryComponentStack;
2222

2323
deprecated module SummaryComponentStack = Impl::Private::SummaryComponentStack;
2424

25-
/** A callable with a flow summary, identified by a unique string. */
26-
abstract class SummarizedCallable extends LibraryCallable, Impl::Public::SummarizedCallable {
27-
bindingset[this]
28-
SummarizedCallable() { any() }
29-
30-
/**
31-
* DEPRECATED: Use `propagatesFlow` instead.
32-
*/
33-
deprecated predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
34-
this.propagatesFlow(input, output, preservesValue, _)
25+
class Provenance = Impl::Public::Provenance;
26+
27+
/** Provides the `Range` class used to define the extent of `SummarizedCallable`. */
28+
module SummarizedCallable {
29+
/** A callable with a flow summary, identified by a unique string. */
30+
abstract class Range extends LibraryCallable, Impl::Public::SummarizedCallable {
31+
bindingset[this]
32+
Range() { any() }
33+
34+
override predicate propagatesFlow(
35+
string input, string output, boolean preservesValue, Provenance p, boolean isExact,
36+
string model
37+
) {
38+
this.propagatesFlow(input, output, preservesValue) and
39+
p = "manual" and
40+
isExact = true and
41+
model = this
42+
}
43+
44+
/**
45+
* Holds if data may flow from `input` to `output` through this callable.
46+
*
47+
* `preservesValue` indicates whether this is a value-preserving step or a taint-step.
48+
*/
49+
predicate propagatesFlow(string input, string output, boolean preservesValue) { none() }
3550
}
51+
}
3652

37-
override predicate propagatesFlow(
38-
string input, string output, boolean preservesValue, string model
39-
) {
40-
this.propagatesFlow(input, output, preservesValue) and model = this
41-
}
53+
final private class SummarizedCallableFinal = SummarizedCallable::Range;
4254

43-
/**
44-
* Holds if data may flow from `input` to `output` through this callable.
45-
*
46-
* `preservesValue` indicates whether this is a value-preserving step or a taint-step.
47-
*/
48-
predicate propagatesFlow(string input, string output, boolean preservesValue) { none() }
49-
}
55+
/** A callable with a flow summary, identified by a unique string. */
56+
final class SummarizedCallable extends SummarizedCallableFinal,
57+
Impl::Public::RelevantSummarizedCallable
58+
{ }
5059

5160
deprecated class RequiredSummaryComponentStack = Impl::Private::RequiredSummaryComponentStack;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ module Input implements InputSig<Location, DataFlowImplSpecific::PythonDataFlow>
1818

1919
class SinkBase = Void;
2020

21+
predicate callableFromSource(SummarizedCallableBase c) { none() }
22+
2123
ArgumentPosition callbackSelfParameterPosition() { result.isLambdaSelf() }
2224

2325
ReturnKind getStandardReturnValueKind() { any() }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private module SummaryTypeTrackerInput implements SummaryTypeTracker::Input {
3030
predicate propagatesFlow(
3131
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
3232
) {
33-
super.propagatesFlow(input, output, preservesValue, _)
33+
super.propagatesFlow(input, output, preservesValue, _, _, _)
3434
}
3535
}
3636

python/ql/lib/semmle/python/frameworks/Flask.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ module Flask {
674674
*
675675
* see https://flask.palletsprojects.com/en/2.3.x/api/#flask.render_template_string
676676
*/
677-
private class RenderTemplateStringSummary extends SummarizedCallable {
677+
private class RenderTemplateStringSummary extends SummarizedCallable::Range {
678678
RenderTemplateStringSummary() { this = "flask.render_template_string" }
679679

680680
override DataFlow::CallCfgNode getACall() {
@@ -700,7 +700,7 @@ module Flask {
700700
*
701701
* see https://flask.palletsprojects.com/en/2.3.x/api/#flask.stream_template_string
702702
*/
703-
private class StreamTemplateStringSummary extends SummarizedCallable {
703+
private class StreamTemplateStringSummary extends SummarizedCallable::Range {
704704
StreamTemplateStringSummary() { this = "flask.stream_template_string" }
705705

706706
override DataFlow::CallCfgNode getACall() {

python/ql/lib/semmle/python/frameworks/Stdlib.qll

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3187,7 +3187,7 @@ module StdlibPrivate {
31873187
*
31883188
* See https://docs.python.org/3.11/library/re.html#re-objects
31893189
*/
3190-
class RePatternSummary extends SummarizedCallable {
3190+
class RePatternSummary extends SummarizedCallable::Range {
31913191
RePatternSummary() { this = "re.Pattern" }
31923192

31933193
override DataFlow::CallCfgNode getACall() {
@@ -3227,7 +3227,7 @@ module StdlibPrivate {
32273227
*
32283228
* See https://docs.python.org/3/library/re.html#re.Match
32293229
*/
3230-
class ReMatchSummary extends SummarizedCallable {
3230+
class ReMatchSummary extends SummarizedCallable::Range {
32313231
ReMatchSummary() { this = ["re.Match", "compiled re.Match"] }
32323232

32333233
override DataFlow::CallCfgNode getACall() {
@@ -3291,7 +3291,7 @@ module StdlibPrivate {
32913291
*
32923292
* See https://docs.python.org/3/library/re.html#re.Match
32933293
*/
3294-
class ReMatchMethodsSummary extends SummarizedCallable {
3294+
class ReMatchMethodsSummary extends SummarizedCallable::Range {
32953295
string methodName;
32963296

32973297
ReMatchMethodsSummary() {
@@ -3335,7 +3335,7 @@ module StdlibPrivate {
33353335
*
33363336
* See https://docs.python.org/3/library/re.html#functions
33373337
*/
3338-
class ReFunctionsSummary extends SummarizedCallable {
3338+
class ReFunctionsSummary extends SummarizedCallable::Range {
33393339
string methodName;
33403340

33413341
ReFunctionsSummary() {
@@ -4183,7 +4183,7 @@ module StdlibPrivate {
41834183
*
41844184
* see https://docs.python.org/3/library/stdtypes.html#dict
41854185
*/
4186-
class DictSummary extends SummarizedCallable {
4186+
class DictSummary extends SummarizedCallable::Range {
41874187
DictSummary() { this = "builtins.dict" }
41884188

41894189
override DataFlow::CallCfgNode getACall() { result = API::builtin("dict").getACall() }
@@ -4222,7 +4222,7 @@ module StdlibPrivate {
42224222
}
42234223

42244224
/** A flow summary for `list`. */
4225-
class ListSummary extends SummarizedCallable {
4225+
class ListSummary extends SummarizedCallable::Range {
42264226
ListSummary() { this = "builtins.list" }
42274227

42284228
override DataFlow::CallCfgNode getACall() { result = API::builtin("list").getACall() }
@@ -4252,7 +4252,7 @@ module StdlibPrivate {
42524252
}
42534253

42544254
/** A flow summary for tuple */
4255-
class TupleSummary extends SummarizedCallable {
4255+
class TupleSummary extends SummarizedCallable::Range {
42564256
TupleSummary() { this = "builtins.tuple" }
42574257

42584258
override DataFlow::CallCfgNode getACall() { result = API::builtin("tuple").getACall() }
@@ -4277,7 +4277,7 @@ module StdlibPrivate {
42774277
}
42784278

42794279
/** A flow summary for set */
4280-
class SetSummary extends SummarizedCallable {
4280+
class SetSummary extends SummarizedCallable::Range {
42814281
SetSummary() { this = "builtins.set" }
42824282

42834283
override DataFlow::CallCfgNode getACall() { result = API::builtin("set").getACall() }
@@ -4307,7 +4307,7 @@ module StdlibPrivate {
43074307
}
43084308

43094309
/** A flow summary for frozenset */
4310-
class FrozensetSummary extends SummarizedCallable {
4310+
class FrozensetSummary extends SummarizedCallable::Range {
43114311
FrozensetSummary() { this = "builtins.frozenset" }
43124312

43134313
override DataFlow::CallCfgNode getACall() { result = API::builtin("frozenset").getACall() }
@@ -4325,7 +4325,7 @@ module StdlibPrivate {
43254325
// Flow summaries for functions operating on containers
43264326
// ---------------------------------------------------------------------------
43274327
/** A flow summary for `reversed`. */
4328-
class ReversedSummary extends SummarizedCallable {
4328+
class ReversedSummary extends SummarizedCallable::Range {
43294329
ReversedSummary() { this = "builtins.reversed" }
43304330

43314331
override DataFlow::CallCfgNode getACall() { result = API::builtin("reversed").getACall() }
@@ -4355,7 +4355,7 @@ module StdlibPrivate {
43554355
}
43564356

43574357
/** A flow summary for `sorted`. */
4358-
class SortedSummary extends SummarizedCallable {
4358+
class SortedSummary extends SummarizedCallable::Range {
43594359
SortedSummary() { this = "builtins.sorted" }
43604360

43614361
override DataFlow::CallCfgNode getACall() { result = API::builtin("sorted").getACall() }
@@ -4387,7 +4387,7 @@ module StdlibPrivate {
43874387
}
43884388

43894389
/** A flow summary for `iter`. */
4390-
class IterSummary extends SummarizedCallable {
4390+
class IterSummary extends SummarizedCallable::Range {
43914391
IterSummary() { this = "builtins.iter" }
43924392

43934393
override DataFlow::CallCfgNode getACall() { result = API::builtin("iter").getACall() }
@@ -4417,7 +4417,7 @@ module StdlibPrivate {
44174417
}
44184418

44194419
/** A flow summary for `next`. */
4420-
class NextSummary extends SummarizedCallable {
4420+
class NextSummary extends SummarizedCallable::Range {
44214421
NextSummary() { this = "builtins.next" }
44224422

44234423
override DataFlow::CallCfgNode getACall() { result = API::builtin("next").getACall() }
@@ -4447,7 +4447,7 @@ module StdlibPrivate {
44474447
}
44484448

44494449
/** A flow summary for `map`. */
4450-
class MapSummary extends SummarizedCallable {
4450+
class MapSummary extends SummarizedCallable::Range {
44514451
MapSummary() { this = "builtins.map" }
44524452

44534453
override DataFlow::CallCfgNode getACall() { result = API::builtin("map").getACall() }
@@ -4482,7 +4482,7 @@ module StdlibPrivate {
44824482
}
44834483

44844484
/** A flow summary for `filter`. */
4485-
class FilterSummary extends SummarizedCallable {
4485+
class FilterSummary extends SummarizedCallable::Range {
44864486
FilterSummary() { this = "builtins.filter" }
44874487

44884488
override DataFlow::CallCfgNode getACall() { result = API::builtin("filter").getACall() }
@@ -4508,7 +4508,7 @@ module StdlibPrivate {
45084508
}
45094509

45104510
/**A summary for `enumerate`. */
4511-
class EnumerateSummary extends SummarizedCallable {
4511+
class EnumerateSummary extends SummarizedCallable::Range {
45124512
EnumerateSummary() { this = "builtins.enumerate" }
45134513

45144514
override DataFlow::CallCfgNode getACall() { result = API::builtin("enumerate").getACall() }
@@ -4534,7 +4534,7 @@ module StdlibPrivate {
45344534
}
45354535

45364536
/** A flow summary for `zip`. */
4537-
class ZipSummary extends SummarizedCallable {
4537+
class ZipSummary extends SummarizedCallable::Range {
45384538
ZipSummary() { this = "builtins.zip" }
45394539

45404540
override DataFlow::CallCfgNode getACall() { result = API::builtin("zip").getACall() }
@@ -4568,7 +4568,7 @@ module StdlibPrivate {
45684568
// Flow summaries for container methods
45694569
// ---------------------------------------------------------------------------
45704570
/** A flow summary for `copy`. */
4571-
class CopySummary extends SummarizedCallable {
4571+
class CopySummary extends SummarizedCallable::Range {
45724572
CopySummary() { this = "collection.copy" }
45734573

45744574
override DataFlow::CallCfgNode getACall() {
@@ -4591,7 +4591,7 @@ module StdlibPrivate {
45914591
}
45924592

45934593
/** A flow summary for `copy.replace`. */
4594-
class ReplaceSummary extends SummarizedCallable {
4594+
class ReplaceSummary extends SummarizedCallable::Range {
45954595
ReplaceSummary() { this = "copy.replace" }
45964596

45974597
override DataFlow::CallCfgNode getACall() {
@@ -4624,7 +4624,7 @@ module StdlibPrivate {
46244624
* I also handles the default value when `pop` is called
46254625
* on a dictionary, since that also does not depend on the key.
46264626
*/
4627-
class PopSummary extends SummarizedCallable {
4627+
class PopSummary extends SummarizedCallable::Range {
46284628
PopSummary() { this = "collection.pop" }
46294629

46304630
override DataFlow::CallCfgNode getACall() {
@@ -4655,7 +4655,7 @@ module StdlibPrivate {
46554655
}
46564656

46574657
/** A flow summary for `dict.pop` */
4658-
class DictPopSummary extends SummarizedCallable {
4658+
class DictPopSummary extends SummarizedCallable::Range {
46594659
string key;
46604660

46614661
DictPopSummary() {
@@ -4678,7 +4678,7 @@ module StdlibPrivate {
46784678
}
46794679

46804680
/** A flow summary for `dict.get` at specific content. */
4681-
class DictGetSummary extends SummarizedCallable {
4681+
class DictGetSummary extends SummarizedCallable::Range {
46824682
string key;
46834683

46844684
DictGetSummary() {
@@ -4706,7 +4706,7 @@ module StdlibPrivate {
47064706
}
47074707

47084708
/** A flow summary for `dict.get` disregarding content. */
4709-
class DictGetAnySummary extends SummarizedCallable {
4709+
class DictGetAnySummary extends SummarizedCallable::Range {
47104710
DictGetAnySummary() { this = "dict.get" }
47114711

47124712
override DataFlow::CallCfgNode getACall() {
@@ -4729,7 +4729,7 @@ module StdlibPrivate {
47294729
}
47304730

47314731
/** A flow summary for `dict.popitem` */
4732-
class DictPopitemSummary extends SummarizedCallable {
4732+
class DictPopitemSummary extends SummarizedCallable::Range {
47334733
DictPopitemSummary() { this = "dict.popitem" }
47344734

47354735
override DataFlow::CallCfgNode getACall() {
@@ -4753,7 +4753,7 @@ module StdlibPrivate {
47534753
*
47544754
* See https://docs.python.org/3.10/library/stdtypes.html#dict.setdefault
47554755
*/
4756-
class DictSetdefaultSummary extends SummarizedCallable {
4756+
class DictSetdefaultSummary extends SummarizedCallable::Range {
47574757
DictSetdefaultSummary() { this = "dict.setdefault" }
47584758

47594759
override DataFlow::CallCfgNode getACall() {
@@ -4778,7 +4778,7 @@ module StdlibPrivate {
47784778
* This summary handles read and store steps. See `DictSetdefaultSummary`
47794779
* for the dataflow steps.
47804780
*/
4781-
class DictSetdefaultKeySummary extends SummarizedCallable {
4781+
class DictSetdefaultKeySummary extends SummarizedCallable::Range {
47824782
string key;
47834783

47844784
DictSetdefaultKeySummary() {
@@ -4811,7 +4811,7 @@ module StdlibPrivate {
48114811
*
48124812
* See https://docs.python.org/3.10/library/stdtypes.html#dict.values
48134813
*/
4814-
class DictValues extends SummarizedCallable {
4814+
class DictValues extends SummarizedCallable::Range {
48154815
DictValues() { this = "dict.values" }
48164816

48174817
override DataFlow::CallCfgNode getACall() {
@@ -4840,7 +4840,7 @@ module StdlibPrivate {
48404840
*
48414841
* See https://docs.python.org/3.10/library/stdtypes.html#dict.keys
48424842
*/
4843-
class DictKeys extends SummarizedCallable {
4843+
class DictKeys extends SummarizedCallable::Range {
48444844
DictKeys() { this = "dict.keys" }
48454845

48464846
override DataFlow::CallCfgNode getACall() { result.(DataFlow::MethodCallNode).calls(_, "keys") }
@@ -4862,7 +4862,7 @@ module StdlibPrivate {
48624862
*
48634863
* See https://docs.python.org/3.10/library/stdtypes.html#dict.items
48644864
*/
4865-
class DictItems extends SummarizedCallable {
4865+
class DictItems extends SummarizedCallable::Range {
48664866
DictItems() { this = "dict.items" }
48674867

48684868
override DataFlow::CallCfgNode getACall() {
@@ -4892,7 +4892,7 @@ module StdlibPrivate {
48924892
*
48934893
* See https://docs.python.org/3.10/library/stdtypes.html#typesseq-mutable
48944894
*/
4895-
class ListAppend extends SummarizedCallable {
4895+
class ListAppend extends SummarizedCallable::Range {
48964896
ListAppend() { this = "list.append" }
48974897

48984898
override DataFlow::CallCfgNode getACall() {
@@ -4921,7 +4921,7 @@ module StdlibPrivate {
49214921
*
49224922
* See https://docs.python.org/3.10/library/stdtypes.html#frozenset.add
49234923
*/
4924-
class SetAdd extends SummarizedCallable {
4924+
class SetAdd extends SummarizedCallable::Range {
49254925
SetAdd() { this = "set.add" }
49264926

49274927
override DataFlow::CallCfgNode getACall() { result.(DataFlow::MethodCallNode).calls(_, "add") }
@@ -4948,7 +4948,7 @@ module StdlibPrivate {
49484948
*
49494949
* See https://devdocs.io/python~3.11/library/os#os.getenv
49504950
*/
4951-
class OsGetEnv extends SummarizedCallable {
4951+
class OsGetEnv extends SummarizedCallable::Range {
49524952
OsGetEnv() { this = "os.getenv" }
49534953

49544954
override DataFlow::CallCfgNode getACall() {

0 commit comments

Comments
 (0)