Skip to content

Commit 49f902d

Browse files
authored
Merge pull request github#4757 from yoff/python-dataflow-synthetic-callables
Python: Enclosing callable for synthetic arguments
2 parents a08eb99 + 0629d3e commit 49f902d

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

python/ql/src/semmle/python/dataflow/new/internal/DataFlowPublic.qll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ class PosOverflowNode extends Node, TPosOverflowNode {
287287

288288
override string toString() { result = "PosOverflowNode for " + call.getNode().toString() }
289289

290+
override DataFlowCallable getEnclosingCallable() {
291+
exists(Node node |
292+
node = TCfgNode(call) and
293+
result = node.getEnclosingCallable()
294+
)
295+
}
296+
290297
override Location getLocation() { result = call.getLocation() }
291298
}
292299

@@ -301,6 +308,13 @@ class KwOverflowNode extends Node, TKwOverflowNode {
301308

302309
override string toString() { result = "KwOverflowNode for " + call.getNode().toString() }
303310

311+
override DataFlowCallable getEnclosingCallable() {
312+
exists(Node node |
313+
node = TCfgNode(call) and
314+
result = node.getEnclosingCallable()
315+
)
316+
}
317+
304318
override Location getLocation() { result = call.getLocation() }
305319
}
306320

@@ -316,6 +330,13 @@ class KwUnpacked extends Node, TKwUnpacked {
316330

317331
override string toString() { result = "KwUnpacked " + name }
318332

333+
override DataFlowCallable getEnclosingCallable() {
334+
exists(Node node |
335+
node = TCfgNode(call) and
336+
result = node.getEnclosingCallable()
337+
)
338+
}
339+
319340
override Location getLocation() { result = call.getLocation() }
320341
}
321342

python/ql/test/experimental/dataflow/consistency/dataflow-consistency.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
uniqueEnclosingCallable
2+
| test.py:239:27:239:27 | ControlFlowNode for p | Node should have one enclosing callable but has 0. |
23
uniqueType
34
uniqueNodeLocation
45
missingLocation

python/ql/test/experimental/dataflow/consistency/test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,17 @@ def non_const_eq_preserves_taint(x):
235235
SINK(tainted) # unsafe
236236
if tainted == x:
237237
SINK(tainted) # unsafe
238+
239+
def overflowCallee(*args, p="", **kwargs):
240+
print("args", args)
241+
print("p", p)
242+
print("kwargs", kwargs)
243+
244+
def synth_arg_posOverflow():
245+
overflowCallee(42)
246+
247+
def synth_arg_kwOverflow():
248+
overflowCallee(foo=42)
249+
250+
def synth_arg_kwUnpacked():
251+
overflowCallee(**{"p": "42"})

0 commit comments

Comments
 (0)