Skip to content

Commit f402475

Browse files
committed
Python: Fix globals() == locals() FP
1 parent 69fe2a3 commit f402475

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

python/ql/src/Statements/ModificationOfLocals.ql

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,11 @@ predicate modification_of_locals(ControlFlowNode f) {
3030
}
3131

3232
from AstNode a, ControlFlowNode f
33-
where modification_of_locals(f) and a = f.getNode()
33+
where
34+
modification_of_locals(f) and
35+
a = f.getNode() and
36+
// in module level scope `locals() == globals()`
37+
// see https://docs.python.org/3/library/functions.html#locals
38+
// FP report in https://github.com/github/codeql/issues/6674
39+
not a.getScope() instanceof ModuleScope
3440
select a, "Modification of the locals() dictionary will have no effect on the local variables."

python/ql/test/query-tests/Statements/general/ModificationOfLocals.expected

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
| test.py:101:5:101:14 | Attribute() | Modification of the locals() dictionary will have no effect on the local variables. |
44
| test.py:102:9:102:14 | Subscript | Modification of the locals() dictionary will have no effect on the local variables. |
55
| test.py:103:5:103:13 | Attribute() | Modification of the locals() dictionary will have no effect on the local variables. |
6-
| test.py:110:1:110:15 | Subscript | Modification of the locals() dictionary will have no effect on the local variables. |

0 commit comments

Comments
 (0)