-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathdict.py
More file actions
123 lines (98 loc) · 2.53 KB
/
dict.py
File metadata and controls
123 lines (98 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# All functions starting with "test_" should run and execute `print("OK")` exactly once.
# This can be checked by running validTest.py.
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname((__file__))))
from testlib import *
# These are defined so that we can evaluate the test code.
NONSOURCE = "not a source"
SOURCE = "source"
def is_source(x):
return x == "source" or x == b"source" or x == 42 or x == 42.0 or x == 42j
def SINK(x):
if is_source(x):
print("OK")
else:
print("Unexpected flow", x)
def SINK_F(x):
if is_source(x):
print("Unexpected flow", x)
else:
print("OK")
def In(tainted):
def captureIn1():
sinkI1 = tainted
SINK(sinkI1) #$ MISSING:captured
captureIn1()
def captureIn2():
def m():
sinkI2 = tainted
SINK(sinkI2) #$ MISSING:captured
m()
captureIn2()
# captureIn3 = lambda arg:(
# sinkI3 = tainted;
# check(sinkI3);
# return arg)
# [ captureIn3(x) for x in " " ]
def captureIn1NotCalled():
nonSink0 = tainted
SINK_F(nonSink0)
def captureIn2NotCalled():
def m():
nonSink0 = tainted
SINK_F(nonSink0)
captureIn2NotCalled()
@expects(2)
def test_In():
In(SOURCE)
def Out():
sinkO1 = { "x": "" }
def captureOut1():
sinkO1["x"] = "source"
captureOut1()
SINK(sinkO1["x"]) #$ MISSING:captured
sinkO2 = { "x": "" }
def captureOut2():
def m():
sinkO2["x"] = "source"
m()
captureOut2()
SINK(sinkO2["x"]) #$ MISSING:captured
nonSink0 = { "x": "" }
def captureOut1NotCalled():
nonSink0["x"] = "source"
SINK_F(nonSink0["x"])
def captureOut2NotCalled():
def m():
nonSink0["x"] = "source"
captureOut2NotCalled()
SINK_F(nonSink0["x"])
@expects(4)
def test_Out():
Out()
def Through(tainted):
sinkO1 = { "x": "" }
def captureOut1():
sinkO1["x"] = tainted
captureOut1()
SINK(sinkO1["x"]) #$ MISSING:captured
sinkO2 = { "x": "" }
def captureOut2():
def m():
sinkO2["x"] = tainted
m()
captureOut2()
SINK(sinkO2["x"]) #$ MISSING:captured
nonSink0 = { "x": "" }
def captureOut1NotCalled():
nonSink0["x"] = tainted
SINK_F(nonSink0["x"])
def captureOut2NotCalled():
def m():
nonSink0["x"] = tainted
captureOut2NotCalled()
SINK_F(nonSink0["x"])
@expects(4)
def test_Through():
Through(SOURCE)