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

Skip to content

Commit e5a361c

Browse files
committed
Python: Better taint tests for copy.deepcopy
1 parent cf2eacd commit e5a361c

2 files changed

Lines changed: 82 additions & 63 deletions

File tree

python/ql/test/experimental/dataflow/tainttracking/defaultAdditionalTaintStep/TestTaint.expected

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,69 @@
1-
| test_collections.py:24 | ok | test_construction | tainted_string |
2-
| test_collections.py:25 | ok | test_construction | tainted_list |
3-
| test_collections.py:26 | ok | test_construction | tainted_tuple |
4-
| test_collections.py:27 | ok | test_construction | tainted_set |
5-
| test_collections.py:28 | ok | test_construction | tainted_dict |
1+
| test_collections.py:23 | ok | test_construction | tainted_string |
2+
| test_collections.py:24 | ok | test_construction | tainted_list |
3+
| test_collections.py:25 | ok | test_construction | tainted_tuple |
4+
| test_collections.py:26 | ok | test_construction | tainted_set |
5+
| test_collections.py:27 | ok | test_construction | tainted_dict |
6+
| test_collections.py:31 | ok | test_construction | list(..) |
67
| test_collections.py:32 | ok | test_construction | list(..) |
78
| test_collections.py:33 | ok | test_construction | list(..) |
89
| test_collections.py:34 | ok | test_construction | list(..) |
910
| test_collections.py:35 | ok | test_construction | list(..) |
10-
| test_collections.py:36 | ok | test_construction | list(..) |
11-
| test_collections.py:38 | ok | test_construction | tuple(..) |
12-
| test_collections.py:39 | ok | test_construction | set(..) |
13-
| test_collections.py:40 | ok | test_construction | frozenset(..) |
14-
| test_collections.py:48 | ok | test_access | tainted_list[0] |
15-
| test_collections.py:49 | ok | test_access | tainted_list[x] |
16-
| test_collections.py:50 | ok | test_access | tainted_list[Slice] |
17-
| test_collections.py:52 | ok | test_access | sorted(..) |
18-
| test_collections.py:53 | ok | test_access | reversed(..) |
19-
| test_collections.py:54 | ok | test_access | iter(..) |
20-
| test_collections.py:55 | ok | test_access | next(..) |
21-
| test_collections.py:56 | ok | test_access | copy(..) |
22-
| test_collections.py:57 | ok | test_access | deepcopy(..) |
23-
| test_collections.py:61 | ok | test_access | a |
24-
| test_collections.py:61 | ok | test_access | b |
25-
| test_collections.py:61 | ok | test_access | c |
26-
| test_collections.py:64 | ok | test_access | h |
27-
| test_collections.py:66 | ok | test_access | i |
28-
| test_collections.py:73 | ok | test_dict_access | tainted_dict["name"] |
29-
| test_collections.py:74 | ok | test_dict_access | tainted_dict.get(..) |
30-
| test_collections.py:75 | ok | test_dict_access | tainted_dict[x] |
31-
| test_collections.py:76 | ok | test_dict_access | tainted_dict.copy() |
32-
| test_collections.py:80 | ok | test_dict_access | v |
33-
| test_collections.py:82 | ok | test_dict_access | v |
34-
| test_collections.py:90 | fail | test_named_tuple | point[0] |
35-
| test_collections.py:91 | fail | test_named_tuple | point.x |
36-
| test_collections.py:95 | ok | test_named_tuple | point[1] |
37-
| test_collections.py:96 | ok | test_named_tuple | point.y |
38-
| test_collections.py:100 | fail | test_named_tuple | a |
39-
| test_collections.py:101 | ok | test_named_tuple | b |
40-
| test_collections.py:109 | fail | test_defaultdict | tainted_default_dict["name"] |
41-
| test_collections.py:110 | fail | test_defaultdict | tainted_default_dict.get(..) |
42-
| test_collections.py:111 | fail | test_defaultdict | tainted_default_dict[x] |
43-
| test_collections.py:112 | fail | test_defaultdict | tainted_default_dict.copy() |
44-
| test_collections.py:115 | fail | test_defaultdict | v |
45-
| test_collections.py:117 | fail | test_defaultdict | v |
46-
| test_collections.py:124 | ok | list_index_assign | my_list |
47-
| test_collections.py:127 | fail | list_index_assign | my_list |
48-
| test_collections.py:134 | ok | list_index_aug_assign | my_list |
49-
| test_collections.py:137 | fail | list_index_aug_assign | my_list |
50-
| test_collections.py:144 | ok | list_append | my_list |
51-
| test_collections.py:147 | fail | list_append | my_list |
52-
| test_collections.py:154 | ok | list_extend | my_list |
53-
| test_collections.py:157 | fail | list_extend | my_list |
54-
| test_collections.py:164 | ok | dict_update_dict | my_dict |
55-
| test_collections.py:167 | fail | dict_update_dict | my_dict |
56-
| test_collections.py:174 | ok | dict_update_kv_list | my_dict |
57-
| test_collections.py:177 | fail | dict_update_kv_list | my_dict |
58-
| test_collections.py:183 | ok | dict_update_kv_arg | my_dict |
59-
| test_collections.py:186 | fail | dict_update_kv_arg | my_dict |
60-
| test_collections.py:193 | ok | dict_manual_update | my_dict |
61-
| test_collections.py:197 | fail | dict_manual_update | my_dict |
62-
| test_collections.py:205 | fail | dict_merge | merged |
63-
| test_collections.py:212 | ok | set_add | my_set |
64-
| test_collections.py:215 | fail | set_add | my_set |
11+
| test_collections.py:37 | ok | test_construction | tuple(..) |
12+
| test_collections.py:38 | ok | test_construction | set(..) |
13+
| test_collections.py:39 | ok | test_construction | frozenset(..) |
14+
| test_collections.py:47 | ok | test_access | tainted_list[0] |
15+
| test_collections.py:48 | ok | test_access | tainted_list[x] |
16+
| test_collections.py:49 | ok | test_access | tainted_list[Slice] |
17+
| test_collections.py:51 | ok | test_access | sorted(..) |
18+
| test_collections.py:52 | ok | test_access | reversed(..) |
19+
| test_collections.py:53 | ok | test_access | iter(..) |
20+
| test_collections.py:54 | ok | test_access | next(..) |
21+
| test_collections.py:58 | ok | test_access | a |
22+
| test_collections.py:58 | ok | test_access | b |
23+
| test_collections.py:58 | ok | test_access | c |
24+
| test_collections.py:61 | ok | test_access | h |
25+
| test_collections.py:63 | ok | test_access | i |
26+
| test_collections.py:70 | ok | test_dict_access | tainted_dict["name"] |
27+
| test_collections.py:71 | ok | test_dict_access | tainted_dict.get(..) |
28+
| test_collections.py:72 | ok | test_dict_access | tainted_dict[x] |
29+
| test_collections.py:73 | ok | test_dict_access | tainted_dict.copy() |
30+
| test_collections.py:77 | ok | test_dict_access | v |
31+
| test_collections.py:79 | ok | test_dict_access | v |
32+
| test_collections.py:87 | fail | test_named_tuple | point[0] |
33+
| test_collections.py:88 | fail | test_named_tuple | point.x |
34+
| test_collections.py:92 | ok | test_named_tuple | point[1] |
35+
| test_collections.py:93 | ok | test_named_tuple | point.y |
36+
| test_collections.py:97 | fail | test_named_tuple | a |
37+
| test_collections.py:98 | ok | test_named_tuple | b |
38+
| test_collections.py:106 | fail | test_defaultdict | tainted_default_dict["name"] |
39+
| test_collections.py:107 | fail | test_defaultdict | tainted_default_dict.get(..) |
40+
| test_collections.py:108 | fail | test_defaultdict | tainted_default_dict[x] |
41+
| test_collections.py:109 | fail | test_defaultdict | tainted_default_dict.copy() |
42+
| test_collections.py:112 | fail | test_defaultdict | v |
43+
| test_collections.py:114 | fail | test_defaultdict | v |
44+
| test_collections.py:121 | ok | test_copy_1 | copy(..) |
45+
| test_collections.py:122 | ok | test_copy_1 | deepcopy(..) |
46+
| test_collections.py:130 | ok | test_copy_2 | copy.copy(..) |
47+
| test_collections.py:131 | ok | test_copy_2 | copy.deepcopy(..) |
48+
| test_collections.py:139 | ok | list_index_assign | my_list |
49+
| test_collections.py:142 | fail | list_index_assign | my_list |
50+
| test_collections.py:149 | ok | list_index_aug_assign | my_list |
51+
| test_collections.py:152 | fail | list_index_aug_assign | my_list |
52+
| test_collections.py:159 | ok | list_append | my_list |
53+
| test_collections.py:162 | fail | list_append | my_list |
54+
| test_collections.py:169 | ok | list_extend | my_list |
55+
| test_collections.py:172 | fail | list_extend | my_list |
56+
| test_collections.py:179 | ok | dict_update_dict | my_dict |
57+
| test_collections.py:182 | fail | dict_update_dict | my_dict |
58+
| test_collections.py:189 | ok | dict_update_kv_list | my_dict |
59+
| test_collections.py:192 | fail | dict_update_kv_list | my_dict |
60+
| test_collections.py:198 | ok | dict_update_kv_arg | my_dict |
61+
| test_collections.py:201 | fail | dict_update_kv_arg | my_dict |
62+
| test_collections.py:208 | ok | dict_manual_update | my_dict |
63+
| test_collections.py:212 | fail | dict_manual_update | my_dict |
64+
| test_collections.py:220 | fail | dict_merge | merged |
65+
| test_collections.py:227 | ok | set_add | my_set |
66+
| test_collections.py:230 | fail | set_add | my_set |
6567
| test_json.py:26 | ok | test | json.dumps(..) |
6668
| test_json.py:27 | ok | test | json.loads(..) |
6769
| test_json.py:34 | fail | test | tainted_filelike |

python/ql/test/experimental/dataflow/tainttracking/defaultAdditionalTaintStep/test_collections.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# Actual tests
1212

1313
from collections import defaultdict, namedtuple
14-
from copy import copy, deepcopy
1514

1615
def test_construction():
1716
tainted_string = TAINTED_STRING
@@ -53,8 +52,6 @@ def test_access(x, y, z):
5352
reversed(tainted_list),
5453
iter(tainted_list),
5554
next(iter(tainted_list)),
56-
copy(tainted_list),
57-
deepcopy(tainted_list)
5855
)
5956

6057
a, b, c = tainted_list[0:3]
@@ -117,6 +114,24 @@ def test_defaultdict(key, x): # TODO: defaultdict currently not handled
117114
ensure_tainted(v)
118115

119116

117+
def test_copy_1():
118+
from copy import copy, deepcopy
119+
120+
ensure_tainted(
121+
copy(TAINTED_LIST),
122+
deepcopy(TAINTED_LIST),
123+
)
124+
125+
126+
def test_copy_2():
127+
import copy
128+
129+
ensure_tainted(
130+
copy.copy(TAINTED_LIST),
131+
copy.deepcopy(TAINTED_LIST),
132+
)
133+
134+
120135
def list_index_assign():
121136
tainted_string = TAINTED_STRING
122137
my_list = ["safe"]
@@ -222,6 +237,8 @@ def set_add():
222237
test_dict_access("name")
223238
test_named_tuple()
224239
test_defaultdict("key", "key")
240+
test_copy_1()
241+
test_copy_2()
225242

226243
list_index_assign()
227244
list_index_aug_assign()

0 commit comments

Comments
 (0)