Skip to content

Commit c0ad870

Browse files
committed
Python: Exclude synthetic generator functions from DataFlowCallable
1 parent d86f98d commit c0ad870

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,14 @@ abstract class LibraryCallable extends string {
254254
}
255255

256256
newtype TDataFlowCallable =
257-
TFunction(Function func) or
257+
TFunction(Function func) {
258+
// For generators/list-comprehensions we create a synthetic function. In the
259+
// points-to call-graph these were not considered callable, and instead we added
260+
// data-flow steps (read/write) for these. As an easy solution for now, we do the
261+
// same to keep things easy to reason about (and therefore exclude things that do
262+
// not have a definition)
263+
exists(func.getDefinition())
264+
} or
258265
/** see QLDoc for `DataFlowModuleScope` for why we need this. */
259266
TModule(Module m) or
260267
TLibraryCallable(LibraryCallable callable)

python/ql/test/experimental/dataflow/coverage/localFlow.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@
88
| test.py:187:1:187:53 | GSSA Variable SINK | test.py:189:5:189:8 | ControlFlowNode for SINK |
99
| test.py:187:1:187:53 | GSSA Variable SOURCE | test.py:188:25:188:30 | ControlFlowNode for SOURCE |
1010
| test.py:188:5:188:5 | SSA variable x | test.py:189:10:189:10 | ControlFlowNode for x |
11+
| test.py:188:9:188:68 | ControlFlowNode for .0 | test.py:188:9:188:68 | SSA variable .0 |
1112
| test.py:188:9:188:68 | ControlFlowNode for ListComp | test.py:188:5:188:5 | SSA variable x |
13+
| test.py:188:9:188:68 | SSA variable .0 | test.py:188:9:188:68 | ControlFlowNode for .0 |
14+
| test.py:188:16:188:16 | SSA variable v | test.py:188:45:188:45 | ControlFlowNode for v |
15+
| test.py:188:40:188:40 | SSA variable u | test.py:188:56:188:56 | ControlFlowNode for u |
16+
| test.py:188:51:188:51 | SSA variable z | test.py:188:67:188:67 | ControlFlowNode for z |
17+
| test.py:188:62:188:62 | SSA variable y | test.py:188:10:188:10 | ControlFlowNode for y |

python/ql/test/experimental/dataflow/enclosing-callable/EnclosingCallable.expected

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
| generator.py:0:0:0:0 | Module generator | generator.py:1:1:1:23 | ControlFlowNode for FunctionExpr |
1616
| generator.py:0:0:0:0 | Module generator | generator.py:1:5:1:18 | ControlFlowNode for generator_func |
1717
| generator.py:1:1:1:23 | Function generator_func | generator.py:1:20:1:21 | ControlFlowNode for xs |
18+
| generator.py:1:1:1:23 | Function generator_func | generator.py:2:12:2:26 | ControlFlowNode for .0 |
19+
| generator.py:1:1:1:23 | Function generator_func | generator.py:2:12:2:26 | ControlFlowNode for .0 |
1820
| generator.py:1:1:1:23 | Function generator_func | generator.py:2:12:2:26 | ControlFlowNode for ListComp |
21+
| generator.py:1:1:1:23 | Function generator_func | generator.py:2:13:2:13 | ControlFlowNode for Yield |
22+
| generator.py:1:1:1:23 | Function generator_func | generator.py:2:13:2:13 | ControlFlowNode for x |
23+
| generator.py:1:1:1:23 | Function generator_func | generator.py:2:19:2:19 | ControlFlowNode for x |
1924
| generator.py:1:1:1:23 | Function generator_func | generator.py:2:24:2:25 | ControlFlowNode for xs |
20-
| generator.py:2:12:2:26 | Function listcomp | generator.py:2:12:2:26 | ControlFlowNode for .0 |
21-
| generator.py:2:12:2:26 | Function listcomp | generator.py:2:12:2:26 | ControlFlowNode for .0 |
22-
| generator.py:2:12:2:26 | Function listcomp | generator.py:2:13:2:13 | ControlFlowNode for Yield |
23-
| generator.py:2:12:2:26 | Function listcomp | generator.py:2:13:2:13 | ControlFlowNode for x |
24-
| generator.py:2:12:2:26 | Function listcomp | generator.py:2:19:2:19 | ControlFlowNode for x |

python/ql/test/experimental/dataflow/tainttracking/generator-flow/test_taint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_non_source():
3131
ensure_not_tainted(x)
3232

3333
x = generator_helper(NONSOURCE)
34-
ensure_not_tainted(x) # $ SPURIOUS: tainted
34+
ensure_not_tainted(x)
3535

3636
x = generator_helper_wo_source_use(NONSOURCE)
3737
ensure_not_tainted(x)

0 commit comments

Comments
 (0)