mirror of
https://github.com/github/codeql.git
synced 2025-12-20 18:56:32 +01:00
Python: Remove impossible flow for **kwargs params
This commit is contained in:
@@ -54,6 +54,28 @@ class SyntheticPreUpdateNode extends Node, TSyntheticPreUpdateNode {
|
|||||||
override Location getLocation() { result = node.getLocation() }
|
override Location getLocation() { result = node.getLocation() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures that the a `**kwargs` parameter will not contain elements with names of
|
||||||
|
* keyword parameters.
|
||||||
|
*
|
||||||
|
* For example, for the function below, it's not possible that the `kwargs` dictionary
|
||||||
|
* can contain an element with the name `a`, since that parameter can be given as a
|
||||||
|
* keyword argument.
|
||||||
|
*
|
||||||
|
* ```py
|
||||||
|
* def func(a, **kwargs):
|
||||||
|
* ...
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
private predicate dictSplatParameterNodeClearStep(ParameterNode n, DictionaryElementContent c) {
|
||||||
|
exists(DataFlowCallable callable, ParameterPosition dictSplatPos, ParameterPosition keywordPos |
|
||||||
|
dictSplatPos.isDictSplat() and
|
||||||
|
n = callable.getParameter(dictSplatPos) and
|
||||||
|
exists(callable.getParameter(keywordPos)) and
|
||||||
|
keywordPos.isKeyword(c.getKey())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
abstract class PostUpdateNodeImpl extends Node {
|
abstract class PostUpdateNodeImpl extends Node {
|
||||||
/** Gets the node before the state update. */
|
/** Gets the node before the state update. */
|
||||||
abstract Node getPreUpdateNode();
|
abstract Node getPreUpdateNode();
|
||||||
@@ -673,6 +695,8 @@ predicate clearsContent(Node n, Content c) {
|
|||||||
attributeClearStep(n, c)
|
attributeClearStep(n, c)
|
||||||
or
|
or
|
||||||
FlowSummaryImpl::Private::Steps::summaryClearsContent(n, c)
|
FlowSummaryImpl::Private::Steps::summaryClearsContent(n, c)
|
||||||
|
or
|
||||||
|
dictSplatParameterNodeClearStep(n, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -198,5 +198,5 @@ def test_mixed():
|
|||||||
args = {"b": arg2, "c": "safe"} # $ arg2 func=mixed
|
args = {"b": arg2, "c": "safe"} # $ arg2 func=mixed
|
||||||
mixed(a=arg1, **args) # $ arg1
|
mixed(a=arg1, **args) # $ arg1
|
||||||
|
|
||||||
args = {"a": arg1, "b": arg2, "c": "safe"} # $ bad1="arg1" arg2 func=mixed
|
args = {"a": arg1, "b": arg2, "c": "safe"} # $ arg2 func=mixed MISSING: arg1
|
||||||
mixed(**args)
|
mixed(**args)
|
||||||
|
|||||||
Reference in New Issue
Block a user