Skip to content

Commit 1c611fe

Browse files
authored
Merge pull request #16155 from yoff/python/MaD-method-arg-tests
2 parents 8ccedd6 + 3716b8c commit 1c611fe

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ 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].Instance.Member[instance_method]", "Argument[self]", "ReturnValue.TupleElement[0]", "value"]
22+
- ["foo", "Member[MS_Class].Instance.Member[instance_method]", "Argument[0]", "ReturnValue.TupleElement[1]", "value"]
23+
- ["foo", "Member[MS_Class].Instance.Member[explicit_self]", "Argument[self:]", "ReturnValue", "value"]
2124
- ["json", "Member[MS_loads]", "Argument[0]", "ReturnValue", "taint"]

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ 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].Instance.Member[instance_method]", "Argument[self]", "ReturnValue.TupleElement[0]", "value"]
22+
- ["foo", "Member[MS_Class].Instance.Member[instance_method]", "Argument[0]", "ReturnValue.TupleElement[1]", "value"]
23+
- ["foo", "Member[MS_Class].Instance.Member[explicit_self]", "Argument[self:]", "ReturnValue", "value"]
2124
- ["json", "Member[MS_loads]", "Argument[0]", "ReturnValue", "taint"]

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ 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
126+
127+
c = MS_Class()
128+
a, b = c.instance_method(SOURCE)
129+
SINK_F(a)
130+
SINK(b) # $ flow="SOURCE, l:-2 -> b"
131+
132+
# Call the instance method on the class to expose the self argument
133+
x, y = MS_Class.instance_method(SOURCE, NONSOURCE)
134+
SINK(x) # $ MISSING: flow="SOURCE, l:-1 -> x"
135+
SINK_F(y)
136+
137+
# Call the instance method on the class to expose the self argument
138+
# That self argument is not referenced by `Argument[self:]`
139+
SINK_F(MS_Class.explicit_self(SOURCE))
140+
# Instead, `Argument[self:]` refers to a keyword argument named `self` (which you are allowed to do in Python)
141+
SINK(c.explicit_self(self = SOURCE)) # $ flow="SOURCE -> c.explicit_self(..)"
142+
125143
# Modeled flow-summary is not value preserving
126144
from json import MS_loads as json_loads
127145

0 commit comments

Comments
 (0)