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

Skip to content

Commit b604976

Browse files
committed
Python: Add a few more collection taint tests
1 parent 32f9d30 commit b604976

2 files changed

Lines changed: 39 additions & 22 deletions

File tree

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

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,35 @@
1414
| collections.py:48 | ok | test_access | tainted_list[0] |
1515
| collections.py:49 | ok | test_access | tainted_list[x] |
1616
| collections.py:50 | ok | test_access | tainted_list[Slice] |
17-
| collections.py:54 | fail | test_access | a |
18-
| collections.py:54 | fail | test_access | b |
19-
| collections.py:54 | fail | test_access | c |
20-
| collections.py:57 | fail | test_access | h |
21-
| collections.py:59 | fail | test_access | i |
22-
| collections.py:66 | ok | test_dict_access | tainted_dict["name"] |
23-
| collections.py:67 | ok | test_dict_access | tainted_dict[x] |
24-
| collections.py:68 | fail | test_dict_access | tainted_dict.copy() |
25-
| collections.py:72 | fail | test_dict_access | v |
26-
| collections.py:74 | fail | test_dict_access | v |
27-
| collections.py:82 | fail | test_named_tuple | point[0] |
28-
| collections.py:83 | fail | test_named_tuple | point.x |
29-
| collections.py:87 | ok | test_named_tuple | point[1] |
30-
| collections.py:88 | ok | test_named_tuple | point.y |
31-
| collections.py:92 | fail | test_named_tuple | a |
32-
| collections.py:93 | ok | test_named_tuple | b |
33-
| collections.py:101 | fail | test_defaultdict | tainted_default_dict["name"] |
34-
| collections.py:102 | fail | test_defaultdict | tainted_default_dict[x] |
35-
| collections.py:103 | fail | test_defaultdict | tainted_default_dict.copy() |
36-
| collections.py:106 | fail | test_defaultdict | v |
37-
| collections.py:108 | fail | test_defaultdict | v |
17+
| collections.py:52 | fail | test_access | sorted(..) |
18+
| collections.py:53 | fail | test_access | reversed(..) |
19+
| collections.py:54 | fail | test_access | iter(..) |
20+
| collections.py:55 | fail | test_access | next(..) |
21+
| collections.py:56 | fail | test_access | copy(..) |
22+
| collections.py:57 | ok | test_access | deepcopy(..) |
23+
| collections.py:61 | fail | test_access | a |
24+
| collections.py:61 | fail | test_access | b |
25+
| collections.py:61 | fail | test_access | c |
26+
| collections.py:64 | fail | test_access | h |
27+
| collections.py:66 | fail | test_access | i |
28+
| collections.py:73 | ok | test_dict_access | tainted_dict["name"] |
29+
| collections.py:74 | fail | test_dict_access | tainted_dict.get(..) |
30+
| collections.py:75 | ok | test_dict_access | tainted_dict[x] |
31+
| collections.py:76 | fail | test_dict_access | tainted_dict.copy() |
32+
| collections.py:80 | fail | test_dict_access | v |
33+
| collections.py:82 | fail | test_dict_access | v |
34+
| collections.py:90 | fail | test_named_tuple | point[0] |
35+
| collections.py:91 | fail | test_named_tuple | point.x |
36+
| collections.py:95 | ok | test_named_tuple | point[1] |
37+
| collections.py:96 | ok | test_named_tuple | point.y |
38+
| collections.py:100 | fail | test_named_tuple | a |
39+
| collections.py:101 | ok | test_named_tuple | b |
40+
| collections.py:109 | fail | test_defaultdict | tainted_default_dict["name"] |
41+
| collections.py:110 | fail | test_defaultdict | tainted_default_dict.get(..) |
42+
| collections.py:111 | fail | test_defaultdict | tainted_default_dict[x] |
43+
| collections.py:112 | fail | test_defaultdict | tainted_default_dict.copy() |
44+
| collections.py:115 | fail | test_defaultdict | v |
45+
| collections.py:117 | fail | test_defaultdict | v |
3846
| json.py:26 | ok | test | json.dumps(..) |
3947
| json.py:27 | ok | test | json.loads(..) |
4048
| json.py:34 | fail | test | tainted_filelike |

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# Actual tests
1212

1313
from collections import defaultdict, namedtuple
14-
14+
from copy import copy, deepcopy
1515

1616
def test_construction():
1717
tainted_string = TAINTED_STRING
@@ -48,6 +48,13 @@ def test_access(x, y, z):
4848
tainted_list[0],
4949
tainted_list[x],
5050
tainted_list[y:z],
51+
52+
sorted(tainted_list),
53+
reversed(tainted_list),
54+
iter(tainted_list),
55+
next(iter(tainted_list)),
56+
copy(tainted_list),
57+
deepcopy(tainted_list)
5158
)
5259

5360
a, b, c = tainted_list[0:3]
@@ -64,6 +71,7 @@ def test_dict_access(x):
6471

6572
ensure_tainted(
6673
tainted_dict["name"],
74+
tainted_dict.get("name"),
6775
tainted_dict[x],
6876
tainted_dict.copy(),
6977
)
@@ -99,6 +107,7 @@ def test_defaultdict(key, x): # TODO: defaultdict currently not handled
99107

100108
ensure_tainted(
101109
tainted_default_dict["name"],
110+
tainted_default_dict.get("name"),
102111
tainted_default_dict[x],
103112
tainted_default_dict.copy(),
104113
)

0 commit comments

Comments
 (0)