Python: Remove points-to references from python.qll

For now, these have just been made into `private` imports. After doing
this, I went through all of the (now not compiling) files and added in
private imports to the modules that they actually depended on.

I also added an explicit import of `LegacyPointsTo` (even though it may
be unnecessary) in cases where the points-to dependency was somewhat
surprising (and one we want to get rid of). This was primarily inside
the various SSA layers.

For modules inside `semmle.python.{types, objects, pointsto}` I did not
bother, as these are fairly clearly related to points-to.
This commit is contained in:
Taus
2025-10-30 16:37:28 +00:00
parent 85cb3e026c
commit 78c33ab55a
43 changed files with 73 additions and 39 deletions

View File

@@ -20,8 +20,21 @@
*/ */
private import python private import python
private import semmle.python.pointsto.PointsTo import semmle.python.pointsto.Base
private import semmle.python.objects.Modules import semmle.python.pointsto.Context
import semmle.python.pointsto.PointsTo
import semmle.python.pointsto.PointsToContext
import semmle.python.objects.ObjectAPI
import semmle.python.objects.ObjectInternal
import semmle.python.types.Object
import semmle.python.types.ClassObject
import semmle.python.types.FunctionObject
import semmle.python.types.ModuleObject
import semmle.python.types.Exceptions
import semmle.python.types.Properties
import semmle.python.types.ImportTime
import semmle.python.types.Descriptors
import semmle.python.SelfAttribute
/** /**
* An extension of `ControlFlowNode` that provides points-to predicates. * An extension of `ControlFlowNode` that provides points-to predicates.

View File

@@ -4,7 +4,6 @@
import python import python
private import LegacyPointsTo private import LegacyPointsTo
import semmle.python.pointsto.PointsTo
import IDEContextual import IDEContextual
private newtype TDefinition = private newtype TDefinition =

View File

@@ -19,22 +19,22 @@ import semmle.python.Constants
import semmle.python.Scope import semmle.python.Scope
import semmle.python.Comment import semmle.python.Comment
import semmle.python.GuardedControlFlow import semmle.python.GuardedControlFlow
import semmle.python.types.ImportTime private import semmle.python.types.ImportTime
import semmle.python.types.Object private import semmle.python.types.Object
import semmle.python.types.ClassObject private import semmle.python.types.ClassObject
import semmle.python.types.FunctionObject private import semmle.python.types.FunctionObject
import semmle.python.types.ModuleObject private import semmle.python.types.ModuleObject
import semmle.python.types.Version private import semmle.python.types.Version
import semmle.python.types.Descriptors private import semmle.python.types.Descriptors
import semmle.python.SSA import semmle.python.SSA
import semmle.python.SelfAttribute private import semmle.python.SelfAttribute
import semmle.python.types.Properties private import semmle.python.types.Properties
import semmle.python.xml.XML import semmle.python.xml.XML
import semmle.python.essa.Essa import semmle.python.essa.Essa
import semmle.python.pointsto.Base private import semmle.python.pointsto.Base
import semmle.python.pointsto.Context private import semmle.python.pointsto.Context
import semmle.python.pointsto.CallGraph private import semmle.python.pointsto.CallGraph
import semmle.python.objects.ObjectAPI private import semmle.python.objects.ObjectAPI
import semmle.python.Unit import semmle.python.Unit
import site import site
private import semmle.python.Overlay private import semmle.python.Overlay

View File

@@ -1,6 +1,7 @@
import python import python
private import semmle.python.internal.CachedStages private import semmle.python.internal.CachedStages
private import codeql.controlflow.BasicBlock as BB private import codeql.controlflow.BasicBlock as BB
private import LegacyPointsTo
/* /*
* Note about matching parent and child nodes and CFG splitting: * Note about matching parent and child nodes and CFG splitting:

View File

@@ -1,6 +1,7 @@
/** SSA library */ /** SSA library */
import python import python
private import LegacyPointsTo
/** /**
* A single static assignment variable. * A single static assignment variable.

View File

@@ -5,6 +5,7 @@
import python import python
private import semmle.python.pointsto.Filters private import semmle.python.pointsto.Filters
private import LegacyPointsTo
/** /**
* An attribute access where the left hand side of the attribute expression * An attribute access where the left hand side of the attribute expression

View File

@@ -9,6 +9,7 @@ private import semmle.python.dataflow.new.DataFlow
private import semmle.python.dataflow.new.internal.ImportStar private import semmle.python.dataflow.new.internal.ImportStar
private import semmle.python.dataflow.new.TypeTracking private import semmle.python.dataflow.new.TypeTracking
private import semmle.python.dataflow.new.internal.DataFlowPrivate private import semmle.python.dataflow.new.internal.DataFlowPrivate
private import semmle.python.essa.SsaDefinitions
/** /**
* Python modules and the way imports are resolved are... complicated. Here's a crash course in how * Python modules and the way imports are resolved are... complicated. Here's a crash course in how

View File

@@ -1,6 +1,6 @@
import python import python
import semmle.python.dataflow.TaintTracking import semmle.python.dataflow.TaintTracking
private import semmle.python.objects.ObjectInternal private import LegacyPointsTo
private import semmle.python.dataflow.Implementation private import semmle.python.dataflow.Implementation
module TaintTracking { module TaintTracking {

View File

@@ -1,4 +1,5 @@
import python import python
private import LegacyPointsTo
import semmle.python.dataflow.TaintTracking import semmle.python.dataflow.TaintTracking
class OpenFile extends TaintKind { class OpenFile extends TaintKind {

View File

@@ -1,7 +1,6 @@
import python import python
private import LegacyPointsTo private import LegacyPointsTo
import semmle.python.dataflow.TaintTracking import semmle.python.dataflow.TaintTracking
private import semmle.python.objects.ObjectInternal
private import semmle.python.pointsto.Filters as Filters private import semmle.python.pointsto.Filters as Filters
import semmle.python.dataflow.Legacy import semmle.python.dataflow.Legacy

View File

@@ -9,9 +9,7 @@
*/ */
import python import python
private import semmle.python.pointsto.PointsTo private import LegacyPointsTo
private import semmle.python.pointsto.PointsToContext
private import semmle.python.objects.ObjectInternal
/** A state that should be tracked. */ /** A state that should be tracked. */
abstract class TrackableState extends string { abstract class TrackableState extends string {

View File

@@ -89,7 +89,6 @@
import python import python
private import LegacyPointsTo private import LegacyPointsTo
private import semmle.python.pointsto.Filters as Filters private import semmle.python.pointsto.Filters as Filters
private import semmle.python.objects.ObjectInternal
private import semmle.python.dataflow.Implementation private import semmle.python.dataflow.Implementation
import semmle.python.dataflow.Configuration import semmle.python.dataflow.Configuration

View File

@@ -1,4 +1,5 @@
import semmle.python.dependencies.Dependencies import semmle.python.dependencies.Dependencies
private import LegacyPointsTo
/** /**
* A library describing an abstract mechanism for representing dependency categories. * A library describing an abstract mechanism for representing dependency categories.

View File

@@ -1,6 +1,7 @@
import python import python
import semmle.python.dependencies.Dependencies import semmle.python.dependencies.Dependencies
import semmle.python.dependencies.DependencyKind import semmle.python.dependencies.DependencyKind
private import LegacyPointsTo
/** /**
* Combine the source-file and package into a single string: * Combine the source-file and package into a single string:

View File

@@ -1,5 +1,4 @@
import python import python
/* /*
* Classification of variables. These should be non-overlapping and complete. * Classification of variables. These should be non-overlapping and complete.
* *
@@ -12,6 +11,9 @@ import python
* Escaping globals -- Global variables that have definitions and at least one of those definitions is in another scope. * Escaping globals -- Global variables that have definitions and at least one of those definitions is in another scope.
*/ */
private import LegacyPointsTo
private import semmle.python.essa.SsaDefinitions
/** A source language variable, to be converted into a set of SSA variables. */ /** A source language variable, to be converted into a set of SSA variables. */
abstract class SsaSourceVariable extends @py_variable { abstract class SsaSourceVariable extends @py_variable {
SsaSourceVariable() { SsaSourceVariable() {

View File

@@ -6,6 +6,8 @@ import python
private import SsaCompute private import SsaCompute
import semmle.python.essa.Definitions import semmle.python.essa.Definitions
private import semmle.python.internal.CachedStages private import semmle.python.internal.CachedStages
private import LegacyPointsTo
private import semmle.python.essa.SsaDefinitions
/** An (enhanced) SSA variable derived from `SsaSourceVariable`. */ /** An (enhanced) SSA variable derived from `SsaSourceVariable`. */
class EssaVariable extends TEssaDefinition { class EssaVariable extends TEssaDefinition {

View File

@@ -5,6 +5,7 @@
import python import python
private import semmle.python.internal.CachedStages private import semmle.python.internal.CachedStages
private import LegacyPointsTo
cached cached
module SsaSource { module SsaSource {

View File

@@ -1,7 +1,7 @@
/** Utilities for handling the zope libraries */ /** Utilities for handling the zope libraries */
import python import python
private import semmle.python.pointsto.PointsTo private import LegacyPointsTo
/** A method that belongs to a sub-class of `zope.interface.Interface` */ /** A method that belongs to a sub-class of `zope.interface.Interface` */
class ZopeInterfaceMethodValue extends PythonFunctionValue { class ZopeInterfaceMethodValue extends PythonFunctionValue {

View File

@@ -5,6 +5,7 @@ private import semmle.python.pointsto.PointsTo
private import semmle.python.pointsto.MRO private import semmle.python.pointsto.MRO
private import semmle.python.pointsto.PointsToContext private import semmle.python.pointsto.PointsToContext
private import semmle.python.types.Builtins private import semmle.python.types.Builtins
private import semmle.python.objects.ObjectAPI
/** /**
* A constant. * A constant.

View File

@@ -5,6 +5,7 @@ private import semmle.python.pointsto.PointsTo
private import semmle.python.pointsto.PointsToContext private import semmle.python.pointsto.PointsToContext
private import semmle.python.pointsto.MRO private import semmle.python.pointsto.MRO
private import semmle.python.types.Builtins private import semmle.python.types.Builtins
private import semmle.python.pointsto.Context
/** A property object. */ /** A property object. */
class PropertyInternal extends ObjectInternal, TProperty { class PropertyInternal extends ObjectInternal, TProperty {

View File

@@ -5,6 +5,8 @@ private import semmle.python.pointsto.PointsTo
private import semmle.python.pointsto.MRO private import semmle.python.pointsto.MRO
private import semmle.python.pointsto.PointsToContext private import semmle.python.pointsto.PointsToContext
private import semmle.python.types.Builtins private import semmle.python.types.Builtins
private import semmle.python.pointsto.Context
private import semmle.python.pointsto.Base
/** A class representing instances */ /** A class representing instances */
abstract class InstanceObject extends ObjectInternal { abstract class InstanceObject extends ObjectInternal {

View File

@@ -5,6 +5,7 @@ private import semmle.python.pointsto.PointsTo
private import semmle.python.pointsto.MRO private import semmle.python.pointsto.MRO
private import semmle.python.pointsto.PointsToContext private import semmle.python.pointsto.PointsToContext
private import semmle.python.types.Builtins private import semmle.python.types.Builtins
private import semmle.python.types.ImportTime
/** A class representing modules */ /** A class representing modules */
abstract class ModuleObjectInternal extends ObjectInternal { abstract class ModuleObjectInternal extends ObjectInternal {

View File

@@ -6,9 +6,6 @@
import python import python
private import LegacyPointsTo private import LegacyPointsTo
private import TObject private import TObject
private import semmle.python.objects.ObjectInternal
private import semmle.python.pointsto.PointsTo
private import semmle.python.pointsto.PointsToContext
private import semmle.python.pointsto.MRO private import semmle.python.pointsto.MRO
private import semmle.python.types.Builtins private import semmle.python.types.Builtins

View File

@@ -6,6 +6,7 @@ private import semmle.python.objects.ObjectInternal
private import semmle.python.pointsto.PointsTo private import semmle.python.pointsto.PointsTo
private import semmle.python.pointsto.PointsToContext private import semmle.python.pointsto.PointsToContext
private import semmle.python.internal.CachedStages private import semmle.python.internal.CachedStages
private import semmle.python.pointsto.Context
/** /**
* Internal type backing `ObjectInternal` and `Value` * Internal type backing `ObjectInternal` and `Value`

View File

@@ -12,6 +12,8 @@ import python
import semmle.python.essa.SsaDefinitions import semmle.python.essa.SsaDefinitions
private import semmle.python.types.Builtins private import semmle.python.types.Builtins
private import semmle.python.internal.CachedStages private import semmle.python.internal.CachedStages
private import semmle.python.types.Object
private import semmle.python.types.ClassObject
/* /*
* The following predicates exist in order to provide * The following predicates exist in order to provide

View File

@@ -11,6 +11,8 @@
import python import python
private import semmle.python.pointsto.PointsToContext private import semmle.python.pointsto.PointsToContext
private import semmle.python.types.FunctionObject
private import semmle.python.pointsto.Context
private newtype TTInvocation = private newtype TTInvocation =
TInvocation(FunctionObject f, Context c) { TInvocation(FunctionObject f, Context c) {

View File

@@ -7,6 +7,11 @@ private import semmle.python.pointsto.MRO
private import semmle.python.types.Builtins private import semmle.python.types.Builtins
private import semmle.python.types.Extensions private import semmle.python.types.Extensions
private import semmle.python.internal.CachedStages private import semmle.python.internal.CachedStages
private import semmle.python.types.Object
private import semmle.python.types.FunctionObject
private import semmle.python.types.ClassObject
private import semmle.python.pointsto.Base
private import semmle.python.types.ImportTime
/* Use this version for speed */ /* Use this version for speed */
class CfgOrigin extends @py_object { class CfgOrigin extends @py_object {

View File

@@ -1,6 +1,8 @@
import python import python
private import semmle.python.pointsto.PointsTo private import semmle.python.pointsto.PointsTo
private import semmle.python.objects.ObjectInternal private import semmle.python.objects.ObjectInternal
private import semmle.python.types.ImportTime
private import semmle.python.types.Version
/* /*
* A note on 'cost'. Cost doesn't represent the cost to compute, * A note on 'cost'. Cost doesn't represent the cost to compute,

View File

@@ -1,4 +1,5 @@
import python import python
private import LegacyPointsTo
class Builtin extends @py_cobject { class Builtin extends @py_cobject {
Builtin() { Builtin() {

View File

@@ -6,6 +6,7 @@ private import semmle.python.pointsto.PointsTo
private import semmle.python.pointsto.MRO private import semmle.python.pointsto.MRO
private import semmle.python.types.Builtins private import semmle.python.types.Builtins
private import semmle.python.objects.ObjectInternal private import semmle.python.objects.ObjectInternal
private import semmle.python.types.ImportTime
/** /**
* A class whose instances represents Python classes. * A class whose instances represents Python classes.

View File

@@ -1,5 +1,8 @@
import python import python
private import semmle.python.objects.ObjectInternal private import semmle.python.objects.ObjectInternal
private import semmle.python.types.Object
private import semmle.python.types.FunctionObject
private import semmle.python.pointsto.Context
/** A class method object. Either a decorated function or an explicit call to classmethod(f) */ /** A class method object. Either a decorated function or an explicit call to classmethod(f) */
class ClassMethodObject extends Object { class ClassMethodObject extends Object {

View File

@@ -16,6 +16,7 @@ private import semmle.python.pointsto.PointsToContext
private import semmle.python.objects.TObject private import semmle.python.objects.TObject
/* Make ObjectInternal visible to save extra imports in user code */ /* Make ObjectInternal visible to save extra imports in user code */
import semmle.python.objects.ObjectInternal import semmle.python.objects.ObjectInternal
import semmle.python.pointsto.Context
abstract class PointsToExtension extends @py_flow_node { abstract class PointsToExtension extends @py_flow_node {
string toString() { result = "PointsToExtension with missing toString" } string toString() { result = "PointsToExtension with missing toString" }

View File

@@ -1,10 +1,7 @@
import python import python
private import LegacyPointsTo private import LegacyPointsTo
import semmle.python.types.Exceptions
private import semmle.python.pointsto.PointsTo
private import semmle.python.objects.Callables private import semmle.python.objects.Callables
private import semmle.python.libraries.Zope private import semmle.python.libraries.Zope
private import semmle.python.objects.ObjectInternal
private import semmle.python.types.Builtins private import semmle.python.types.Builtins
/** A function object, whether written in Python or builtin */ /** A function object, whether written in Python or builtin */

View File

@@ -1,4 +1,5 @@
import python import python
private import semmle.python.types.ModuleObject
private predicate is_normal_module(ModuleObject m) { private predicate is_normal_module(ModuleObject m) {
m instanceof BuiltinModuleObject m instanceof BuiltinModuleObject

View File

@@ -2,6 +2,9 @@ import python
private import semmle.python.pointsto.PointsTo private import semmle.python.pointsto.PointsTo
private import semmle.python.objects.ObjectInternal private import semmle.python.objects.ObjectInternal
private import semmle.python.types.ModuleKind private import semmle.python.types.ModuleKind
private import semmle.python.types.Object
private import semmle.python.types.ClassObject
private import semmle.python.objects.ObjectAPI
abstract class ModuleObject extends Object { abstract class ModuleObject extends Object {
ModuleValue theModule() { ModuleValue theModule() {

View File

@@ -1,6 +1,5 @@
import python import python
private import LegacyPointsTo private import LegacyPointsTo
private import semmle.python.objects.ObjectInternal
private import semmle.python.types.Builtins private import semmle.python.types.Builtins
private import semmle.python.internal.CachedStages private import semmle.python.internal.CachedStages

View File

@@ -1,8 +1,5 @@
import python import python
private import LegacyPointsTo private import LegacyPointsTo
private import semmle.python.types.Object
private import semmle.python.types.ClassObject
private import semmle.python.types.FunctionObject
predicate string_attribute_all(ControlFlowNodeWithPointsTo n, string attr) { predicate string_attribute_all(ControlFlowNodeWithPointsTo n, string attr) {
(n.getNode() instanceof Unicode or n.getNode() instanceof Bytes) and (n.getNode() instanceof Unicode or n.getNode() instanceof Bytes) and

View File

@@ -13,7 +13,6 @@
import python import python
private import LegacyPointsTo private import LegacyPointsTo
import semmle.python.pointsto.PointsTo
predicate rhs_in_expr(ControlFlowNode rhs, Compare cmp) { predicate rhs_in_expr(ControlFlowNode rhs, Compare cmp) {
exists(Cmpop op, int i | cmp.getOp(i) = op and cmp.getComparator(i) = rhs.getNode() | exists(Cmpop op, int i | cmp.getOp(i) = op and cmp.getComparator(i) = rhs.getNode() |

View File

@@ -3,6 +3,7 @@
import python import python
private import LegacyPointsTo private import LegacyPointsTo
private import semmle.python.objects.ObjectInternal private import semmle.python.objects.ObjectInternal
private import semmle.python.objects.ObjectAPI
/** Holds if the comparison `comp` uses `is` or `is not` (represented as `op`) to compare its `left` and `right` arguments. */ /** Holds if the comparison `comp` uses `is` or `is not` (represented as `op`) to compare its `left` and `right` arguments. */
predicate comparison_using_is(Compare comp, ControlFlowNode left, Cmpop op, ControlFlowNode right) { predicate comparison_using_is(Compare comp, ControlFlowNode left, Cmpop op, ControlFlowNode right) {

View File

@@ -14,6 +14,7 @@
import python import python
private import LegacyPointsTo private import LegacyPointsTo
private import semmle.python.objects.ObjectAPI
predicate assignment(AssignStmt a, Expr left, Expr right) { predicate assignment(AssignStmt a, Expr left, Expr right) {
a.getATarget() = left and a.getValue() = right a.getATarget() = left and a.getValue() = right

View File

@@ -14,7 +14,6 @@ import python
private import LegacyPointsTo private import LegacyPointsTo
import Variables.MonkeyPatched import Variables.MonkeyPatched
import Loop import Loop
import semmle.python.pointsto.PointsTo
predicate guarded_against_name_error(Name u) { predicate guarded_against_name_error(Name u) {
exists(Try t | t.getBody().getAnItem().contains(u) | exists(Try t | t.getBody().getAnItem().contains(u) |

View File

@@ -14,7 +14,6 @@
import python import python
private import LegacyPointsTo private import LegacyPointsTo
import Undefined import Undefined
import semmle.python.pointsto.PointsTo
predicate uninitialized_local(NameNode use) { predicate uninitialized_local(NameNode use) {
exists(FastLocalVariable local | use.uses(local) or use.deletes(local) | exists(FastLocalVariable local | use.uses(local) or use.deletes(local) |

View File

@@ -5,8 +5,6 @@
import python import python
private import LegacyPointsTo private import LegacyPointsTo
import semmle.python.pointsto.PointsTo
import semmle.python.pointsto.PointsToContext
predicate trivial(ControlFlowNode f) { predicate trivial(ControlFlowNode f) {
f.getNode() instanceof Parameter f.getNode() instanceof Parameter