Skip to content

Commit aa382ac

Browse files
committed
Python: Add test for strange generator taint flow
I did check, and this was not a problem with the old call-graph on main! I'm absolutely baffled!
1 parent 36e8b8b commit aa382ac

File tree

6 files changed

+79
-0
lines changed

6 files changed

+79
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
argumentToEnsureNotTaintedNotMarkedAsSpurious
2+
untaintedArgumentToEnsureTaintedNotMarkedAsMissing
3+
failures
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import experimental.meta.InlineTaintTest
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
missingAnnotationOnSink
2+
failures
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import python
2+
import experimental.dataflow.TestUtil.NormalDataflowTest
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
def normal_helper(arg):
2+
l = [arg]
3+
return l[0]
4+
5+
6+
def generator_helper(arg):
7+
l = [arg]
8+
l = [x for x in l]
9+
return l[0]
10+
11+
12+
def generator_helper_wo_source_use(arg):
13+
l = [arg]
14+
l = [x for x in l]
15+
return l[0]
16+
17+
18+
def test_source():
19+
x = normal_helper(SOURCE)
20+
SINK(x) # $ flow="SOURCE, l:-1 -> x"
21+
22+
x = generator_helper(SOURCE)
23+
SINK(x) # $ flow="SOURCE, l:-1 -> x"
24+
25+
26+
def test_non_source():
27+
x = normal_helper(NONSOURCE)
28+
SINK_F(x)
29+
30+
x = generator_helper(NONSOURCE)
31+
SINK_F(x)
32+
33+
x = generator_helper_wo_source_use(NONSOURCE)
34+
SINK_F(x)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
def normal_helper(arg):
2+
l = [arg]
3+
return l[0]
4+
5+
# we had a regression where flow from a source to the argument of this function would
6+
# cause _all_ returns from this function to be treated as tainted. That is, the
7+
# `generator_helper(NONSOURCE)` call in `test_non_source` would result in taint :| This
8+
# is specific to taint-tracking, and does NOT appear in pure data-flow (see the
9+
# test_dataflow file)
10+
def generator_helper(arg):
11+
l = [arg]
12+
l = [x for x in l]
13+
return l[0]
14+
15+
16+
def generator_helper_wo_source_use(arg):
17+
l = [arg]
18+
l = [x for x in l]
19+
return l[0]
20+
21+
def test_source():
22+
x = normal_helper(TAINTED_STRING)
23+
ensure_tainted(x) # $ tainted
24+
25+
x = generator_helper(TAINTED_STRING)
26+
ensure_tainted(x) # $ tainted
27+
28+
29+
def test_non_source():
30+
x = normal_helper(NONSOURCE)
31+
ensure_not_tainted(x)
32+
33+
x = generator_helper(NONSOURCE)
34+
ensure_not_tainted(x) # $ SPURIOUS: tainted
35+
36+
x = generator_helper_wo_source_use(NONSOURCE)
37+
ensure_not_tainted(x)

0 commit comments

Comments
 (0)