Skip to content

Commit c1b2561

Browse files
committed
Python: Extend fieldflow tests with bound method call
1 parent 0f34752 commit c1b2561

File tree

1 file changed

+34
-0
lines changed
  • python/ql/test/experimental/dataflow/fieldflow

1 file changed

+34
-0
lines changed

python/ql/test/experimental/dataflow/fieldflow/test.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,40 @@ def test_nested_obj_method():
160160
a.getObj().foo = x
161161
SINK(a.obj.foo) # $ flow="SOURCE, l:-3 -> a.obj.foo"
162162

163+
# ------------------------------------------------------------------------------
164+
# Bound Method calls
165+
# ------------------------------------------------------------------------------
166+
167+
class Foo:
168+
def __init__(self, x):
169+
self.x = x
170+
171+
def update_x(self, x):
172+
self.x = x
173+
174+
@expects(7) # $ unresolved_call=expects(..) unresolved_call=expects(..)(..)
175+
def test_bound_method_call():
176+
# direct assignment
177+
foo = Foo(None)
178+
SINK_F(foo.x)
179+
foo.x = SOURCE
180+
SINK(foo.x) # $ flow="SOURCE, l:-1 -> foo.x"
181+
foo.x = None
182+
SINK_F(foo.x)
183+
184+
# assignment through function
185+
foo = Foo(SOURCE)
186+
SINK(foo.x) # $ flow="SOURCE, l:-1 -> foo.x"
187+
foo.update_x(None)
188+
SINK_F(foo.x) # $ flow="SOURCE, l:-3 -> foo.x"
189+
190+
# assignment through bound-method calls
191+
foo = Foo(SOURCE)
192+
ux = foo.update_x
193+
SINK(foo.x) # $ flow="SOURCE, l:-2 -> foo.x"
194+
ux(None)
195+
SINK_F(foo.x) # $ SPURIOUS: flow="SOURCE, l:-4 -> foo.x"
196+
163197
# ------------------------------------------------------------------------------
164198
# Global scope
165199
# ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)