Skip to content

Commit e16405c

Browse files
committed
Python: Add test for copy.replace
This test demonstrates the current state of affairs: that `copy.replace` essentially blocks all flow of taint through it, because it has not been modelled yet.
1 parent 24d98ee commit e16405c

File tree

1 file changed

+28
-0
lines changed
  • python/ql/test/library-tests/dataflow/tainttracking/defaultAdditionalTaintStep

1 file changed

+28
-0
lines changed

python/ql/test/library-tests/dataflow/tainttracking/defaultAdditionalTaintStep/test_collections.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,34 @@ def test_copy_2():
166166
copy.deepcopy(TAINTED_LIST), # $ tainted
167167
)
168168

169+
def test_replace():
170+
from copy import replace
171+
172+
class C:
173+
def __init__(self, always_tainted, tainted_to_safe, safe_to_tainted, always_safe):
174+
self.always_tainted = always_tainted
175+
self.tainted_to_safe = tainted_to_safe
176+
self.safe_to_tainted = safe_to_tainted
177+
self.always_safe = always_safe
178+
179+
c = C(always_tainted=TAINTED_STRING,
180+
tainted_to_safe=TAINTED_STRING,
181+
safe_to_tainted=NOT_TAINTED,
182+
always_safe=NOT_TAINTED)
183+
184+
d = replace(c, tainted_to_safe=NOT_TAINTED, safe_to_tainted=TAINTED_STRING)
185+
186+
ensure_tainted(d.always_tainted) # $ MISSING: tainted
187+
ensure_tainted(d.safe_to_tainted) # $ MISSING: tainted
188+
ensure_not_tainted(d.always_safe)
189+
190+
# Currently, we have no way of stopping the value in the tainted_to_safe field (which gets
191+
# overwritten) from flowing through the replace call, which means we get a spurious result.
192+
193+
ensure_not_tainted(d.tainted_to_safe) # $
194+
195+
196+
169197

170198
def list_index_assign():
171199
tainted_string = TAINTED_STRING

0 commit comments

Comments
 (0)