Skip to content

Commit bf34b07

Browse files
committed
Python: Add a few taint tests for default sanitizer
specifically the ones removes from dataflow tests in yoff#1
1 parent 8e86d56 commit bf34b07

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| test.py:16 | fail | const_eq_clears_taint | ts |
2+
| test.py:18 | ok | const_eq_clears_taint | ts |
3+
| test.py:24 | fail | const_eq_clears_taint2 | ts |
4+
| test.py:29 | ok | non_const_eq_preserves_taint | ts |
5+
| test.py:31 | ok | non_const_eq_preserves_taint | ts |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import experimental.dataflow.tainttracking.TestTaintLib
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Add taintlib to PATH so it can be imported during runtime without any hassle
2+
import sys; import os; sys.path.append(os.path.dirname(os.path.dirname((__file__))))
3+
from taintlib import *
4+
5+
# This has no runtime impact, but allows autocomplete to work
6+
from typing import TYPE_CHECKING
7+
if TYPE_CHECKING:
8+
from ..taintlib import *
9+
10+
11+
# Actual tests
12+
13+
def const_eq_clears_taint():
14+
ts = TAINTED_STRING
15+
if ts == "safe":
16+
ensure_not_tainted(ts)
17+
# ts should still be tainted after exiting the if block
18+
ensure_tainted(ts)
19+
20+
def const_eq_clears_taint2():
21+
ts = TAINTED_STRING
22+
if ts != "safe":
23+
return
24+
ensure_not_tainted(ts)
25+
26+
def non_const_eq_preserves_taint(x="foo"):
27+
ts = TAINTED_STRING
28+
if ts == ts:
29+
ensure_tainted(ts)
30+
if ts == x:
31+
ensure_tainted(ts)
32+
33+
34+
# Make tests runable
35+
36+
const_eq_clears_taint()
37+
const_eq_clears_taint2()
38+
non_const_eq_preserves_taint()

0 commit comments

Comments
 (0)