Skip to content

Commit e5e8ec6

Browse files
committed
Python: Add a few test-cases for barrier guards and references
I'm not sure references is the best name, but it's the best I could come up with jsut now
1 parent 5aa2c2f commit e5e8ec6

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ test_taint
3434
| test_logical.py:128 | ok | test_nesting_not_with_and_true | s |
3535
| test_logical.py:137 | fail | test_with_return | s |
3636
| test_logical.py:146 | fail | test_with_exception | s |
37+
| test_reference.py:31 | fail | test_basic | s2 |
38+
| test_reference.py:31 | ok | test_basic | s |
39+
| test_reference.py:33 | ok | test_basic | s |
40+
| test_reference.py:33 | ok | test_basic | s2 |
41+
| test_reference.py:41 | fail | test_identical_call | s.strip() |
42+
| test_reference.py:43 | ok | test_identical_call | s.strip() |
43+
| test_reference.py:56 | fail | test_class_attribute_access | c.foo |
44+
| test_reference.py:58 | ok | test_class_attribute_access | c.foo |
3745
isSanitizer
3846
| TestTaintTrackingConfiguration | test.py:21:39:21:39 | ControlFlowNode for s |
3947
| TestTaintTrackingConfiguration | test.py:50:10:50:29 | ControlFlowNode for emulated_escaping() |
@@ -48,3 +56,6 @@ isSanitizerGuard
4856
| TestTaintTrackingConfiguration | test_logical.py:115:12:115:21 | ControlFlowNode for is_safe() |
4957
| TestTaintTrackingConfiguration | test_logical.py:120:16:120:25 | ControlFlowNode for is_safe() |
5058
| TestTaintTrackingConfiguration | test_logical.py:125:20:125:29 | ControlFlowNode for is_safe() |
59+
| TestTaintTrackingConfiguration | test_reference.py:30:8:30:17 | ControlFlowNode for is_safe() |
60+
| TestTaintTrackingConfiguration | test_reference.py:40:8:40:25 | ControlFlowNode for is_safe() |
61+
| TestTaintTrackingConfiguration | test_reference.py:55:8:55:21 | ControlFlowNode for is_safe() |
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import sys; import os; sys.path.append(os.path.dirname(os.path.dirname((__file__))))
2+
from taintlib import *
3+
4+
# This has no runtime impact, but allows autocomplete to work
5+
from typing import TYPE_CHECKING
6+
if TYPE_CHECKING:
7+
from ..taintlib import *
8+
9+
10+
# Actual tests
11+
12+
"""Testing logical constructs not/and/or works out of the box.
13+
"""
14+
15+
import random
16+
17+
18+
def random_choice():
19+
return bool(random.randint(0, 1))
20+
21+
22+
def is_safe(arg):
23+
return arg == "safe"
24+
25+
26+
def test_basic():
27+
s = TAINTED_STRING
28+
s2 = s
29+
30+
if is_safe(s):
31+
ensure_not_tainted(s, s2)
32+
else:
33+
ensure_tainted(s, s2)
34+
35+
36+
def test_identical_call():
37+
"""This code pattern is being used in real world code"""
38+
s = TAINTED_STRING
39+
40+
if is_safe(s.strip()):
41+
ensure_not_tainted(s.strip())
42+
else:
43+
ensure_tainted(s.strip())
44+
45+
46+
class C(object):
47+
def __init__(self, value):
48+
self.foo = value
49+
50+
51+
def test_class_attribute_access():
52+
s = TAINTED_STRING
53+
c = C(s)
54+
55+
if is_safe(c.foo):
56+
ensure_not_tainted(c.foo)
57+
else:
58+
ensure_tainted(c.foo)
59+
60+
61+
# Make tests runable
62+
63+
test_basic()
64+
test_identical_call()
65+
test_class_attribute_access()

0 commit comments

Comments
 (0)