Skip to content

Commit ea3cc51

Browse files
authored
Merge pull request #16194 from yoff/python/test-constructor-MaD-path
Python: test the MaD path for constructor calls
2 parents 8dc9c95 + 538d556 commit ea3cc51

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

python/ql/test/library-tests/dataflow/model-summaries/InlineTaintTest.ext.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extensions:
1818
- ["foo", "Member[MS_spread]", "Argument[0]", "ReturnValue.TupleElement[0]", "value"]
1919
- ["foo", "Member[MS_spread]", "Argument[1]", "ReturnValue.TupleElement[1]", "value"]
2020
- ["foo", "Member[MS_spread_all]", "Argument[0]", "ReturnValue.TupleElement[0,1]", "value"]
21+
- ["foo", "Member[MS_Class].Call", "Argument[0, x:]", "ReturnValue.Attribute[config]", "value"]
22+
- ["foo", "Member[MS_Class_transitive].Subclass.Call", "Argument[0, x:]", "ReturnValue.Attribute[config]", "value"]
2123
- ["foo", "Member[MS_Class].Instance.Member[instance_method]", "Argument[self]", "ReturnValue.TupleElement[0]", "value"]
2224
- ["foo", "Member[MS_Class].Instance.Member[instance_method]", "Argument[0]", "ReturnValue.TupleElement[1]", "value"]
2325
- ["foo", "Member[MS_Class].Instance.Member[explicit_self]", "Argument[self:]", "ReturnValue", "value"]

python/ql/test/library-tests/dataflow/model-summaries/NormalDataflowTest.ext.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extensions:
1818
- ["foo", "Member[MS_spread]", "Argument[0]", "ReturnValue.TupleElement[0]", "value"]
1919
- ["foo", "Member[MS_spread]", "Argument[1]", "ReturnValue.TupleElement[1]", "value"]
2020
- ["foo", "Member[MS_spread_all]", "Argument[0]", "ReturnValue.TupleElement[0,1]", "value"]
21+
- ["foo", "Member[MS_Class].Call", "Argument[0, x:]", "ReturnValue.Attribute[config]", "value"]
22+
- ["foo", "Member[MS_Class_transitive].Subclass.Call", "Argument[0, x:]", "ReturnValue.Attribute[config]", "value"]
2123
- ["foo", "Member[MS_Class].Instance.Member[instance_method]", "Argument[self]", "ReturnValue.TupleElement[0]", "value"]
2224
- ["foo", "Member[MS_Class].Instance.Member[instance_method]", "Argument[0]", "ReturnValue.TupleElement[1]", "value"]
2325
- ["foo", "Member[MS_Class].Instance.Member[explicit_self]", "Argument[self:]", "ReturnValue", "value"]

python/ql/test/library-tests/dataflow/model-summaries/model_summaries.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,40 @@ def explicit_identity(x):
122122
SINK(a) # $ flow="SOURCE, l:-1 -> a"
123123
SINK(b) # $ flow="SOURCE, l:-2 -> b"
124124

125-
from foo import MS_Class
125+
from foo import MS_Class, MS_Class_transitive
126+
127+
# Class summaries
128+
class_via_positional = MS_Class(SOURCE)
129+
SINK(class_via_positional.config) # $ flow="SOURCE, l:-1 -> class_via_positional.config"
130+
131+
class_via_kw = MS_Class(x = SOURCE)
132+
SINK(class_via_kw.config) # $ flow="SOURCE, l:-1 -> class_via_kw.config"
133+
134+
class C(MS_Class_transitive):
135+
pass
136+
137+
subclass_via_positional = C(SOURCE)
138+
SINK(subclass_via_positional.config) # $ flow="SOURCE, l:-1 -> subclass_via_positional.config"
139+
140+
subclass_via_kw = C(x = SOURCE)
141+
SINK(subclass_via_kw.config) # $ flow="SOURCE, l:-1 -> subclass_via_kw.config"
142+
143+
class D(MS_Class_transitive):
144+
def __init__(x, y):
145+
# special handling of y
146+
super().__init__(x)
147+
148+
SINK(D(SOURCE, NONSOURCE).config) # $ flow="SOURCE -> D(..).config"
149+
SINK(D(x = SOURCE, y = NONSOURCE).config) # $ flow="SOURCE -> D(..).config"
150+
151+
class E(MS_Class_transitive):
152+
# Notice the swapped order of the arguments
153+
def __init__(y, x):
154+
# special handling of y
155+
super().__init__(x)
156+
157+
SINK(E(NONSOURCE, SOURCE).config) # $ MISSING: flow="SOURCE -> E(..).config"
158+
SINK(E(x = SOURCE, y = NONSOURCE).config) # $ flow="SOURCE -> E(..).config"
126159

127160
c = MS_Class()
128161
a, b = c.instance_method(SOURCE)

0 commit comments

Comments
 (0)