mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Python: Remove points-to from Module
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
private import python
|
||||
private import semmle.python.pointsto.PointsTo
|
||||
private import semmle.python.objects.Modules
|
||||
|
||||
/**
|
||||
* An extension of `ControlFlowNode` that provides points-to predicates.
|
||||
@@ -191,3 +192,19 @@ class ExprWithPointsTo extends Expr {
|
||||
|
||||
override string getAQlClass() { none() }
|
||||
}
|
||||
|
||||
/**
|
||||
* An extension of `Module` that provides points-to related methods.
|
||||
*/
|
||||
class ModuleWithPointsTo extends Module {
|
||||
/** Gets a name exported by this module, that is the names that will be added to a namespace by 'from this-module import *' */
|
||||
string getAnExport() {
|
||||
py_exports(this, result)
|
||||
or
|
||||
exists(ModuleObjectInternal mod | mod.getSource() = this.getEntryNode() |
|
||||
mod.(ModuleValue).exports(result)
|
||||
)
|
||||
}
|
||||
|
||||
override string getAQlClass() { none() }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import python
|
||||
private import semmle.python.objects.Modules
|
||||
private import semmle.python.internal.CachedStages
|
||||
|
||||
/**
|
||||
@@ -66,15 +65,6 @@ class Module extends Module_, Scope, AstNode {
|
||||
/** Whether this module is a package initializer */
|
||||
predicate isPackageInit() { this.getName().matches("%\\_\\_init\\_\\_") and not this.isPackage() }
|
||||
|
||||
/** Gets a name exported by this module, that is the names that will be added to a namespace by 'from this-module import *' */
|
||||
string getAnExport() {
|
||||
py_exports(this, result)
|
||||
or
|
||||
exists(ModuleObjectInternal mod | mod.getSource() = this.getEntryNode() |
|
||||
mod.(ModuleValue).exports(result)
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets the source file for this module */
|
||||
File getFile() { py_module_path(this, result) }
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
import Definition
|
||||
|
||||
/**
|
||||
@@ -58,7 +59,7 @@ predicate unused_global(Name unused, GlobalVariable v) {
|
||||
// indirectly
|
||||
defn.getBasicBlock().reachesExit() and u.getScope() != unused.getScope()
|
||||
) and
|
||||
not unused.getEnclosingModule().getAnExport() = v.getId() and
|
||||
not unused.getEnclosingModule().(ModuleWithPointsTo).getAnExport() = v.getId() and
|
||||
not exists(unused.getParentNode().(ClassDef).getDefinedClass().getADecorator()) and
|
||||
not exists(unused.getParentNode().(FunctionDef).getDefinedFunction().getADecorator()) and
|
||||
unused.defines(v) and
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Module m
|
||||
from ModuleWithPointsTo m
|
||||
select m.toString(), m.getAnExport().toString()
|
||||
|
||||
Reference in New Issue
Block a user