mirror of
https://github.com/github/codeql.git
synced 2026-05-15 03:39:32 +02:00
Python: Port UninitializedLocal.ql
Uses the new ExceptionTypes machinery. No test changes.
This commit is contained in:
@@ -2322,6 +2322,11 @@ module ExceptionTypes {
|
||||
BaseException() { name = "BaseException" }
|
||||
}
|
||||
|
||||
/** The builtin `NameError` exception type. */
|
||||
class NameError extends BuiltinExceptType {
|
||||
NameError() { name = "NameError" }
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if the exception edge from `r` to `handler` is unlikely because
|
||||
* none of the exception types that `r` may raise are handled by `handler`.
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
private import semmle.python.dataflow.new.internal.DataFlowDispatch
|
||||
import Undefined
|
||||
|
||||
predicate uninitialized_local(NameNode use) {
|
||||
@@ -21,16 +21,16 @@ predicate uninitialized_local(NameNode use) {
|
||||
) and
|
||||
(
|
||||
any(Uninitialized uninit).taints(use) and
|
||||
PointsToInternal::reachableBlock(use.getBasicBlock(), _)
|
||||
Reachability::likelyReachable(use.getBasicBlock())
|
||||
or
|
||||
not exists(EssaVariable var | var.getASourceUse() = use)
|
||||
)
|
||||
}
|
||||
|
||||
predicate explicitly_guarded(NameNode u) {
|
||||
exists(Try t |
|
||||
exists(Try t, ExceptionTypes::NameError nameError |
|
||||
t.getBody().contains(u.getNode()) and
|
||||
t.getAHandler().getType().(ExprWithPointsTo).pointsTo(ClassValue::nameError())
|
||||
nameError.getAUse().asExpr() = t.getAHandler().getType()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user