mirror of
https://github.com/github/codeql.git
synced 2026-07-29 06:46:46 +02:00
Python: address CodeQL alerts
This commit is contained in:
@@ -156,7 +156,7 @@ module Ast implements AstSig<Py::Location> {
|
||||
/**
|
||||
* A parameter of a callable.
|
||||
*
|
||||
* Modelled per the C# template (`csharp/.../ControlFlowGraph.qll`):
|
||||
* modeled per the C# template (`csharp/.../ControlFlowGraph.qll`):
|
||||
* each Python parameter (the `Py::Parameter` AST node, which is a `Name`
|
||||
* or — Python 2 only — a `Tuple` in store context) becomes a CFG node
|
||||
* at a stable position in the enclosing callable's entry sequence.
|
||||
@@ -766,7 +766,7 @@ module Ast implements AstSig<Py::Location> {
|
||||
/**
|
||||
* A `from m import *` statement. Evaluates the module expression but
|
||||
* binds no name (the bindings happen by side-effect at runtime, which
|
||||
* is not modelled at the CFG level).
|
||||
* is not modeled at the CFG level).
|
||||
*/
|
||||
additional class ImportStarStmt extends Stmt {
|
||||
private Py::ImportStar imp;
|
||||
@@ -921,7 +921,7 @@ module Ast implements AstSig<Py::Location> {
|
||||
* latter flattens a tuple of exception types (`except (A, B):`) into
|
||||
* its individual elements, which would yield several patterns for one
|
||||
* handler and violate the shared CFG's single-pattern-per-catch
|
||||
* contract. The raw child is the one tuple node, modelling the
|
||||
* contract. The raw child is the one tuple node, modeling the
|
||||
* runtime's single `isinstance(exc, (A, B))` test.
|
||||
*/
|
||||
AstNode getPattern() {
|
||||
@@ -1231,7 +1231,7 @@ module Ast implements AstSig<Py::Location> {
|
||||
}
|
||||
|
||||
/**
|
||||
* An `import x.y` module expression. Modelled as a leaf — the dotted
|
||||
* An `import x.y` module expression. modeled as a leaf — the dotted
|
||||
* name is just a string.
|
||||
*/
|
||||
additional class ImportExpression extends Expr {
|
||||
@@ -1629,9 +1629,9 @@ private module Input implements InputSig1, InputSig2 {
|
||||
private string assertThrowTag() { result = "[assert-throw]" }
|
||||
|
||||
/**
|
||||
* Holds if the AST node `n` may raise an exception at runtime as part of
|
||||
* Holds if the expression node `e` may raise an exception at runtime as part of
|
||||
* its normal evaluation (not via an explicit `raise`/`assert`, which are
|
||||
* modelled separately).
|
||||
* modeled separately).
|
||||
*
|
||||
* The set mirrors what the legacy CFG used to flag implicitly: function
|
||||
* calls (anything can raise), attribute access (`AttributeError`),
|
||||
@@ -1640,7 +1640,7 @@ private module Input implements InputSig1, InputSig2 {
|
||||
* (`ImportError`/`ModuleNotFoundError`), and generator/coroutine
|
||||
* suspension points (`await`/`yield`/`yield from`).
|
||||
*
|
||||
* Bare `Name` reads are intentionally excluded — modelling every name
|
||||
* Bare `Name` reads are intentionally excluded — modeling every name
|
||||
* read as `mayThrow` would explode CFG edge count for negligible
|
||||
* analysis value. `BoolExpr`/`IfExp` containers are also excluded; the
|
||||
* operands they evaluate contribute their own exception edges.
|
||||
@@ -1677,7 +1677,7 @@ private module Input implements InputSig1, InputSig2 {
|
||||
private predicate stmtMayThrow(Py::Stmt s) { s instanceof Py::ImportStar }
|
||||
|
||||
/**
|
||||
* Holds if `n` is syntactically inside the body, handlers, `else`, or
|
||||
* Holds if `py` is syntactically inside the body, handlers, `else`, or
|
||||
* `finally` of a `try` statement (or the body of a `with` statement,
|
||||
* which compiles to an implicit try/finally for `__exit__`) in the
|
||||
* same scope.
|
||||
@@ -1701,7 +1701,7 @@ private module Input implements InputSig1, InputSig2 {
|
||||
* `exprMayThrow` and `stmtMayThrow` for the included AST classes.
|
||||
*
|
||||
* Restricted to nodes inside a `try`/`with` statement: matches Java's
|
||||
* approach of only modelling exception flow where it can be observed
|
||||
* approach of only modeling exception flow where it can be observed
|
||||
* by local handling.
|
||||
*/
|
||||
private predicate mayThrow(Ast::AstNode n) {
|
||||
|
||||
@@ -859,7 +859,7 @@ class ExceptGroupFlowNode extends ControlFlowNode {
|
||||
ControlFlowNode getName() { result = this }
|
||||
}
|
||||
|
||||
/** Abstract base class for sequence nodes (tuple, list). */
|
||||
/** A control flow node corresponding to a sequence (tuple, list). */
|
||||
abstract class SequenceNode extends ControlFlowNode {
|
||||
/** Gets the `n`th element of this sequence. */
|
||||
abstract ControlFlowNode getElement(int n);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/** New-CFG version of AllLiveReachable. */
|
||||
|
||||
import python
|
||||
import TimerUtils
|
||||
import NewCfgImpl
|
||||
|
||||
private module Utils = EvalOrderCfgUtils<NewCfg>;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
import TimerUtils
|
||||
import NewCfgImpl
|
||||
|
||||
private module Utils = EvalOrderCfgUtils<NewCfg>;
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
import TimerUtils
|
||||
import NewCfgImpl
|
||||
|
||||
private module Utils = EvalOrderCfgUtils<NewCfg>;
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
import TimerUtils
|
||||
import NewCfgImpl
|
||||
|
||||
private module Utils = EvalOrderCfgUtils<NewCfg>;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* * `match` statements: each `case` body is a syntactically distinct
|
||||
* sub-tree, and the branches don't reconverge through a common
|
||||
* annotation point in the timeline;
|
||||
* * `try` / `with` and `raise` / `assert`: exception edges are modelled
|
||||
* * `try` / `with` and `raise` / `assert`: exception edges are modeled
|
||||
* as true/false but flow to syntactically distinct handlers, with no
|
||||
* reconvergence in the linear annotation order;
|
||||
* * short-circuit `and` / `or` (`BoolExpr`): the branches reconverge at
|
||||
@@ -33,7 +33,6 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
import TimerUtils
|
||||
import NewCfgImpl
|
||||
|
||||
private module Utils = EvalOrderCfgUtils<NewCfg>;
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
import TimerUtils
|
||||
import NewCfgImpl
|
||||
|
||||
private module Utils = EvalOrderCfgUtils<NewCfg>;
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
import TimerUtils
|
||||
import NewCfgImpl
|
||||
|
||||
private module Utils = EvalOrderCfgUtils<NewCfg>;
|
||||
|
||||
@@ -74,9 +74,7 @@ module NewCfg implements EvalOrderCfgSig {
|
||||
|
||||
Py::Scope getScope() { result = NewControlFlowNode.super.getEnclosingCallable().asScope() }
|
||||
|
||||
BasicBlock getBasicBlock() {
|
||||
exists(NewBasicBlock bb, int i | bb.getNode(i) = this and result = bb)
|
||||
}
|
||||
BasicBlock getBasicBlock() { exists(NewBasicBlock bb | bb.getNode(_) = this and result = bb) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
import TimerUtils
|
||||
import NewCfgImpl
|
||||
|
||||
private module Utils = EvalOrderCfgUtils<NewCfg>;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
import TimerUtils
|
||||
import NewCfgImpl
|
||||
|
||||
private module Utils = EvalOrderCfgUtils<NewCfg>;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
import TimerUtils
|
||||
import NewCfgImpl
|
||||
|
||||
private module Utils = EvalOrderCfgUtils<NewCfg>;
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
import TimerUtils
|
||||
import NewCfgImpl
|
||||
|
||||
private module Utils = EvalOrderCfgUtils<NewCfg>;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
import TimerUtils
|
||||
import NewCfgImpl
|
||||
|
||||
private module Utils = EvalOrderCfgUtils<NewCfg>;
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
* Python control flow graph.
|
||||
*/
|
||||
|
||||
private import python as Py
|
||||
private import python as PY
|
||||
import TimerUtils
|
||||
|
||||
/** Existing Python CFG implementation of the evaluation-order signature. */
|
||||
module OldCfg implements EvalOrderCfgSig {
|
||||
class CfgNode = Py::ControlFlowNode;
|
||||
class CfgNode = PY::ControlFlowNode;
|
||||
|
||||
class BasicBlock = Py::BasicBlock;
|
||||
class BasicBlock = PY::BasicBlock;
|
||||
|
||||
CfgNode scopeGetEntryNode(Py::Scope s) { result = s.getEntryNode() }
|
||||
CfgNode scopeGetEntryNode(PY::Scope s) { result = s.getEntryNode() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user