Skip to content

Commit c89b579

Browse files
committed
Python: Change variable capture tests to use fresh variable names
Instead of reusing `nonSink0` for both captureOut1NotCalled and captureOut2NotCalled tests (I used 1/2 naming scheme to match things up nicely). I also added a comment highlighting that `m` is the function that is not called (since I overlooked that initially :O)
1 parent 54ced06 commit c89b579

File tree

4 files changed

+53
-41
lines changed

4 files changed

+53
-41
lines changed

python/ql/test/experimental/dataflow/variable-capture/dict.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,18 @@ def m():
7777
captureOut2()
7878
SINK(sinkO2["x"]) #$ MISSING:captured
7979

80-
nonSink0 = { "x": "" }
80+
nonSink1 = { "x": "" }
8181
def captureOut1NotCalled():
82-
nonSink0["x"] = tainted
83-
SINK_F(nonSink0["x"])
82+
nonSink1["x"] = tainted
83+
SINK_F(nonSink1["x"])
8484

85+
nonSink2 = { "x": "" }
8586
def captureOut2NotCalled():
87+
# notice that `m` is not called
8688
def m():
87-
nonSink0["x"] = tainted
89+
nonSink2["x"] = tainted
8890
captureOut2NotCalled()
89-
SINK_F(nonSink0["x"])
91+
SINK_F(nonSink2["x"])
9092

9193
@expects(4)
9294
def test_through():

python/ql/test/experimental/dataflow/variable-capture/global.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def SINK_F(x):
3434

3535
sinkO1 = ""
3636
sinkO2 = ""
37-
nonSink0 = ""
37+
nonSink1 = ""
38+
nonSink2 = ""
3839

3940
def out():
4041
def captureOut1():
@@ -52,24 +53,26 @@ def m():
5253
SINK(sinkO2) #$ captured
5354

5455
def captureOut1NotCalled():
55-
global nonSink0
56-
nonSink0 = SOURCE
57-
SINK_F(nonSink0) #$ SPURIOUS: captured
56+
global nonSink1
57+
nonSink1 = SOURCE
58+
SINK_F(nonSink1) #$ SPURIOUS: captured
5859

5960
def captureOut2NotCalled():
61+
# notice that `m` is not called
6062
def m():
61-
global nonSink0
62-
nonSink0 = SOURCE
63+
global nonSink2
64+
nonSink2 = SOURCE
6365
captureOut2NotCalled()
64-
SINK_F(nonSink0) #$ SPURIOUS: captured
66+
SINK_F(nonSink2) #$ SPURIOUS: captured
6567

6668
@expects(4)
6769
def test_out():
6870
out()
6971

7072
sinkT1 = ""
7173
sinkT2 = ""
72-
nonSinkT0 = ""
74+
nonSinkT1 = ""
75+
nonSinkT2 = ""
7376
def through(tainted):
7477
def captureOut1():
7578
global sinkT1
@@ -86,16 +89,17 @@ def m():
8689
SINK(sinkT2) #$ MISSING:captured
8790

8891
def captureOut1NotCalled():
89-
global nonSinkT0
90-
nonSinkT0 = tainted
91-
SINK_F(nonSinkT0)
92+
global nonSinkT1
93+
nonSinkT1 = tainted
94+
SINK_F(nonSinkT1)
9295

9396
def captureOut2NotCalled():
97+
# notice that `m` is not called
9498
def m():
95-
global nonSinkT0
96-
nonSinkT0 = tainted
99+
global nonSinkT2
100+
nonSinkT2 = tainted
97101
captureOut2NotCalled()
98-
SINK_F(nonSinkT0)
102+
SINK_F(nonSinkT2)
99103

100104
@expects(4)
101105
def test_through():

python/ql/test/experimental/dataflow/variable-capture/in.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ def m():
4848
captureIn3("")
4949

5050
def captureIn1NotCalled():
51-
nonSink0 = tainted
52-
SINK_F(nonSink0)
51+
nonSink1 = tainted
52+
SINK_F(nonSink1)
5353

5454
def captureIn2NotCalled():
55+
# notice that `m` is not called
5556
def m():
56-
nonSink0 = tainted
57-
SINK_F(nonSink0)
57+
nonSink1 = tainted
58+
SINK_F(nonSink1)
5859
captureIn2NotCalled()
5960

6061
@expects(3)
@@ -81,13 +82,14 @@ def m():
8182
captureIn3("")
8283

8384
def captureIn1NotCalled():
84-
nonSink0 = tainted
85-
SINK_F(nonSink0)
85+
nonSink1 = tainted
86+
SINK_F(nonSink1)
8687

8788
def captureIn2NotCalled():
89+
# notice that `m` is not called
8890
def m():
89-
nonSink0 = tainted
90-
SINK_F(nonSink0)
91+
nonSink2 = tainted
92+
SINK_F(nonSink2)
9193
captureIn2NotCalled()
9294

9395
@expects(3)

python/ql/test/experimental/dataflow/variable-capture/nonlocal.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,20 @@ def m():
4949
captureOut2()
5050
SINK(sinkO2) #$ MISSING:captured
5151

52-
nonSink0 = ""
52+
nonSink1 = ""
5353
def captureOut1NotCalled():
54-
nonlocal nonSink0
55-
nonSink0 = SOURCE
56-
SINK_F(nonSink0)
54+
nonlocal nonSink1
55+
nonSink1 = SOURCE
56+
SINK_F(nonSink1)
5757

58+
nonSink2 = ""
5859
def captureOut2NotCalled():
60+
# notice that `m` is not called
5961
def m():
60-
nonlocal nonSink0
61-
nonSink0 = SOURCE
62+
nonlocal nonSink2
63+
nonSink2 = SOURCE
6264
captureOut2NotCalled()
63-
SINK_F(nonSink0)
65+
SINK_F(nonSink2)
6466

6567
@expects(4)
6668
def test_out():
@@ -83,18 +85,20 @@ def m():
8385
captureOut2()
8486
SINK(sinkO2) #$ MISSING:captured
8587

86-
nonSink0 = ""
88+
nonSink1 = ""
8789
def captureOut1NotCalled():
88-
nonlocal nonSink0
89-
nonSink0 = tainted
90-
SINK_F(nonSink0)
90+
nonlocal nonSink1
91+
nonSink1 = tainted
92+
SINK_F(nonSink1)
9193

94+
nonSink2 = ""
9295
def captureOut2NotCalled():
96+
# notice that `m` is not called
9397
def m():
94-
nonlocal nonSink0
95-
nonSink0 = tainted
98+
nonlocal nonSink2
99+
nonSink2 = tainted
96100
captureOut2NotCalled()
97-
SINK_F(nonSink0)
101+
SINK_F(nonSink2)
98102

99103
@expects(4)
100104
def test_through():

0 commit comments

Comments
 (0)