Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b11b578

Browse files
committed
Python: Adtop more complete tests from old dataflow impl
The ones in test/experimental/dataflow/[consistency,regression]/test.py was a copy from test/library-tests/taint/dataflow/test.py. However, test/library-tests/taint/dataflow/test.py only contains a subset of test/library-tests/taint/config/test.py, that only contains a subset of test/library-tests/taint/general/test.py This commit updates the experimental dataflow tests to be a copy of the test/library-tests/taint/general/test.py file. There seems to have been a few changes to the file after it being copied, in `test_truth` and `test_early_exit`. I have no reproduced those changes.
1 parent c507b33 commit b11b578

2 files changed

Lines changed: 136 additions & 4 deletions

File tree

  • python/ql/test/experimental/dataflow

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

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ def test16():
104104
t = module.dangerous_func()
105105
SINK(t)
106106

107+
class C(object): pass
108+
109+
def x_sink(arg):
110+
SINK(arg.x)
111+
112+
def test17():
113+
t = C()
114+
t.x = module.dangerous
115+
SINK(t.x)
116+
117+
def test18():
118+
t = C()
119+
t.x = module.dangerous
120+
t = hub(t)
121+
x_sink(t)
122+
123+
def test19():
124+
t = CUSTOM_SOURCE
125+
t = hub(TAINT_FROM_ARG(t))
126+
CUSTOM_SINK(t)
107127

108128
def test20(cond):
109129
if cond:
@@ -163,9 +183,55 @@ def test_truth():
163183
if t:
164184
SINK(t)
165185
else:
166-
SINK(t) # Regression: FP here
186+
SINK(t)
187+
if not t:
188+
SINK(t)
189+
else:
190+
SINK(t)
191+
192+
def test_early_exit():
193+
t = FALSEY
167194
if not t:
168-
SINK(t) # Regression: FP here
195+
return
196+
t
197+
198+
def flow_through_type_test_if_no_class():
199+
t = SOURCE
200+
if isinstance(t, str):
201+
SINK(t)
169202
else:
170203
SINK(t)
171204

205+
def flow_in_iteration():
206+
t = ITERABLE_SOURCE
207+
for i in t:
208+
i
209+
return i
210+
211+
def flow_in_generator():
212+
seq = [SOURCE]
213+
for i in seq:
214+
yield i
215+
216+
def flow_from_generator():
217+
for x in flow_in_generator():
218+
SINK(x)
219+
220+
def const_eq_clears_taint():
221+
tainted = SOURCE
222+
if tainted == "safe":
223+
SINK(tainted) # safe
224+
SINK(tainted) # unsafe
225+
226+
def const_eq_clears_taint2():
227+
tainted = SOURCE
228+
if tainted != "safe":
229+
return
230+
SINK(tainted) # safe
231+
232+
def non_const_eq_preserves_taint(x):
233+
tainted = SOURCE
234+
if tainted == tainted:
235+
SINK(tainted) # unsafe
236+
if tainted == x:
237+
SINK(tainted) # unsafe

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

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ def test16():
100100
t = module.dangerous_func()
101101
SINK(t)
102102

103+
class C(object): pass
104+
105+
def x_sink(arg):
106+
SINK(arg.x)
107+
108+
def test17():
109+
t = C()
110+
t.x = module.dangerous
111+
SINK(t.x)
112+
113+
def test18():
114+
t = C()
115+
t.x = module.dangerous
116+
t = hub(t)
117+
x_sink(t)
118+
119+
def test19():
120+
t = CUSTOM_SOURCE
121+
t = hub(TAINT_FROM_ARG(t))
122+
CUSTOM_SINK(t)
103123

104124
def test20(cond):
105125
if cond:
@@ -159,9 +179,55 @@ def test_truth():
159179
if t:
160180
SINK(t)
161181
else:
162-
SINK(t) # Regression: FP here
182+
SINK(t)
183+
if not t:
184+
SINK(t)
185+
else:
186+
SINK(t)
187+
188+
def test_early_exit():
189+
t = FALSEY
163190
if not t:
164-
SINK(t) # Regression: FP here
191+
return
192+
t
193+
194+
def flow_through_type_test_if_no_class():
195+
t = SOURCE
196+
if isinstance(t, str):
197+
SINK(t)
165198
else:
166199
SINK(t)
167200

201+
def flow_in_iteration():
202+
t = ITERABLE_SOURCE
203+
for i in t:
204+
i
205+
return i
206+
207+
def flow_in_generator():
208+
seq = [SOURCE]
209+
for i in seq:
210+
yield i
211+
212+
def flow_from_generator():
213+
for x in flow_in_generator():
214+
SINK(x)
215+
216+
def const_eq_clears_taint():
217+
tainted = SOURCE
218+
if tainted == "safe":
219+
SINK(tainted) # safe
220+
SINK(tainted) # unsafe
221+
222+
def const_eq_clears_taint2():
223+
tainted = SOURCE
224+
if tainted != "safe":
225+
return
226+
SINK(tainted) # safe
227+
228+
def non_const_eq_preserves_taint(x):
229+
tainted = SOURCE
230+
if tainted == tainted:
231+
SINK(tainted) # unsafe
232+
if tainted == x:
233+
SINK(tainted) # unsafe

0 commit comments

Comments
 (0)