Merge pull request #12590 from yoff/python/patch-uninitialized-local

Python: Patch uninitialized local query
This commit is contained in:
yoff
2023-03-20 15:11:14 +01:00
committed by GitHub
3 changed files with 21 additions and 1 deletions

View File

@@ -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(), _)

View File

@@ -0,0 +1,4 @@
---
category: fix
---
* Nonlocal variables are excluded from alerts.

View File

@@ -0,0 +1,14 @@
#!/usr/bin/python
def topLevel():
foo = 3
def bar():
nonlocal foo
print(foo)
foo = 4
bar()
print(foo)
topLevel()