mirror of
https://github.com/github/codeql.git
synced 2026-02-25 19:33:42 +01:00
Moves the existing points-to predicates to the newly added class `ControlFlowNodeWithPointsTo` which resides in the `LegacyPointsTo` module. (Existing code that uses these predicates should import this module, and references to `ControlFlowNode` should be changed to `ControlFlowNodeWithPointsTo`.) Also updates all existing points-to based code to do just this.
42 lines
1.2 KiB
Plaintext
42 lines
1.2 KiB
Plaintext
/**
|
|
* @name Modification of dictionary returned by locals()
|
|
* @description Modifications of the dictionary returned by locals() are not propagated to the local variables of a function.
|
|
* @kind problem
|
|
* @tags quality
|
|
* reliability
|
|
* correctness
|
|
* @problem.severity warning
|
|
* @sub-severity low
|
|
* @precision very-high
|
|
* @id py/modification-of-locals
|
|
*/
|
|
|
|
import python
|
|
private import LegacyPointsTo
|
|
|
|
predicate originIsLocals(ControlFlowNodeWithPointsTo n) {
|
|
n.pointsTo(_, _, Value::named("locals").getACall())
|
|
}
|
|
|
|
predicate modification_of_locals(ControlFlowNode f) {
|
|
originIsLocals(f.(SubscriptNode).getObject()) and
|
|
(f.isStore() or f.isDelete())
|
|
or
|
|
exists(string mname, AttrNode attr |
|
|
attr = f.(CallNode).getFunction() and
|
|
originIsLocals(attr.getObject(mname))
|
|
|
|
|
mname in ["pop", "popitem", "update", "clear"]
|
|
)
|
|
}
|
|
|
|
from AstNode a, ControlFlowNode f
|
|
where
|
|
modification_of_locals(f) and
|
|
a = f.getNode() and
|
|
// in module level scope `locals() == globals()`
|
|
// see https://docs.python.org/3/library/functions.html#locals
|
|
// FP report in https://github.com/github/codeql/issues/6674
|
|
not a.getScope() instanceof ModuleScope
|
|
select a, "Modification of the locals() dictionary will have no effect on the local variables."
|