mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Merge pull request #12590 from yoff/python/patch-uninitialized-local
Python: Patch uninitialized local query
This commit is contained in:
@@ -15,7 +15,9 @@ import Undefined
|
||||
import semmle.python.pointsto.PointsTo
|
||||
|
||||
predicate uninitialized_local(NameNode use) {
|
||||
exists(FastLocalVariable local | use.uses(local) or use.deletes(local) | not local.escapes()) and
|
||||
exists(FastLocalVariable local | use.uses(local) or use.deletes(local) |
|
||||
not local.escapes() and not local = any(Nonlocal nl).getAVariable()
|
||||
) and
|
||||
(
|
||||
any(Uninitialized uninit).taints(use) and
|
||||
PointsToInternal::reachableBlock(use.getBasicBlock(), _)
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: fix
|
||||
---
|
||||
* Nonlocal variables are excluded from alerts.
|
||||
14
python/ql/test/query-tests/Variables/undefined/captured.py
Normal file
14
python/ql/test/query-tests/Variables/undefined/captured.py
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
def topLevel():
|
||||
foo = 3
|
||||
|
||||
def bar():
|
||||
nonlocal foo
|
||||
print(foo)
|
||||
foo = 4
|
||||
|
||||
bar()
|
||||
print(foo)
|
||||
|
||||
topLevel()
|
||||
Reference in New Issue
Block a user