Python: Remove points-to to from ControlFlowNode

Moves the existing points-to predicates to the newly added class
`ControlFlowNodeWithPointsTo` which resides in the `LegacyPointsTo`
module.

(Existing code that uses these predicates should import this module, and
references to `ControlFlowNode` should be changed to
`ControlFlowNodeWithPointsTo`.)

Also updates all existing points-to based code to do just this.
This commit is contained in:
Taus
2025-10-29 22:05:43 +00:00
parent 4461be180a
commit fef08afff9
75 changed files with 410 additions and 236 deletions

View File

@@ -1,6 +1,7 @@
import python
private import LegacyPointsTo
import semmle.python.objects.Modules
from Value val, ControlFlowNode f
from Value val, ControlFlowNodeWithPointsTo f
where f.pointsTo(val)
select f, val

View File

@@ -1,5 +1,6 @@
import python
private import LegacyPointsTo
from CallNode call, Value func
where call.getFunction().pointsTo(func)
where call.getFunction().(ControlFlowNodeWithPointsTo).pointsTo(func)
select call.getLocation().getStartLine(), call.toString(), func.toString()

View File

@@ -1,6 +1,7 @@
import python
private import LegacyPointsTo
from int line, ControlFlowNode f, Value v
from int line, ControlFlowNodeWithPointsTo f, Value v
where
any(ExprStmt s).getValue() = f.getNode() and
line = f.getLocation().getStartLine() and

View File

@@ -1,10 +1,11 @@
import python
private import LegacyPointsTo
// We don't care about the internals of functools which vary from
// version to version, just the end result.
from NameNode f, Object o, ControlFlowNode x, int line
where
f.refersTo(o, x) and
f.(ControlFlowNodeWithPointsTo).refersTo(o, x) and
f.getLocation().getFile().getBaseName() = "test.py" and
line = f.getLocation().getStartLine()
select line, f.toString(), o.toString(), x.getLocation().toString()

View File

@@ -1,7 +1,8 @@
import python
private import LegacyPointsTo
import interesting
from int line, ControlFlowNode f, Object o, ImportTimeScope n
from int line, ControlFlowNodeWithPointsTo f, Object o, ImportTimeScope n
where
of_interest(f, line) and
f.refersTo(o) and

View File

@@ -6,10 +6,11 @@
*/
import python
private import LegacyPointsTo
import interesting
import Util
from int line, ControlFlowNode f, Object o
from int line, ControlFlowNodeWithPointsTo f, Object o
where
of_interest(f, line) and
f.refersTo(o)

View File

@@ -1,8 +1,9 @@
import python
private import LegacyPointsTo
import interesting
import Util
from int line, ControlFlowNode f, Object o, ClassObject cls
from int line, ControlFlowNodeWithPointsTo f, Object o, ClassObject cls
where
of_interest(f, line) and
f.refersTo(o, cls, _)

View File

@@ -1,6 +1,7 @@
import python
private import LegacyPointsTo
from ControlFlowNode f, Object o, ControlFlowNode x
from ControlFlowNodeWithPointsTo f, Object o, ControlFlowNode x
where
f.refersTo(o, x) and
exists(CallNode call | call.getFunction().getNode().(Name).getId() = "use" and call.getArg(0) = f)

View File

@@ -1,6 +1,7 @@
import python
private import LegacyPointsTo
from ControlFlowNode f, Object o, ClassObject c, ControlFlowNode x
from ControlFlowNodeWithPointsTo f, Object o, ClassObject c, ControlFlowNode x
where
f.refersTo(o, c, x) and
exists(CallNode call | call.getFunction().getNode().(Name).getId() = "use" and call.getArg(0) = f)

View File

@@ -1,5 +1,6 @@
import python
private import LegacyPointsTo
from ControlFlowNode f, Context ctx, Value v, ControlFlowNode origin
from ControlFlowNodeWithPointsTo f, Context ctx, Value v, ControlFlowNode origin
where f.pointsTo(ctx, v, origin)
select f, ctx, v

View File

@@ -1,6 +1,7 @@
import python
private import LegacyPointsTo
from ControlFlowNode f, Object o, ControlFlowNode x
from ControlFlowNodeWithPointsTo f, Object o, ControlFlowNode x
where
f.refersTo(o, x) and
f.getLocation().getFile().getBaseName() = "test.py"

View File

@@ -1,6 +1,7 @@
import python
private import LegacyPointsTo
from ControlFlowNode f, Object o, ClassObject c, ControlFlowNode x
from ControlFlowNodeWithPointsTo f, Object o, ClassObject c, ControlFlowNode x
where
f.refersTo(o, c, x) and
f.getLocation().getFile().getBaseName() = "test.py"

View File

@@ -1,5 +1,6 @@
import python
private import LegacyPointsTo
from NameNode n, Object value, ClassObject cls
where n.getId() = "self" and n.refersTo(value, cls, _)
where n.getId() = "self" and n.(ControlFlowNodeWithPointsTo).refersTo(value, cls, _)
select n.getNode().getLocation().getStartLine(), value.toString(), cls.toString()

View File

@@ -4,10 +4,11 @@
*/
private import python
private import LegacyPointsTo
import semmle.python.dataflow.new.DataFlow
predicate pointsToOrigin(DataFlow::CfgNode pointer, DataFlow::CfgNode origin) {
origin.getNode() = pointer.getNode().pointsTo().getOrigin()
origin.getNode() = pointer.getNode().(ControlFlowNodeWithPointsTo).pointsTo().getOrigin()
}
module PointsToConfig implements DataFlow::ConfigSig {

View File

@@ -1,6 +1,7 @@
import python
private import LegacyPointsTo
import Util
from ControlFlowNode f, ControlFlowNode x
from ControlFlowNodeWithPointsTo f, ControlFlowNode x
where f.refersTo(theNoneObject(), _, x)
select locate(f.getLocation(), "abcdghijklmopqr"), f.toString(), x.getLocation().getStartLine()

View File

@@ -1,7 +1,8 @@
import python
private import LegacyPointsTo
import Util
from ControlFlowNode f, Context ctx, Value v, ControlFlowNode origin
from ControlFlowNodeWithPointsTo f, Context ctx, Value v, ControlFlowNode origin
where f.pointsTo(ctx, v, origin)
select locate(f.getLocation(), "abeghijklmnpqrstu"), f.toString(), ctx, vrepr(v),
vrepr(v.getClass())

View File

@@ -1,4 +1,5 @@
import python
private import LegacyPointsTo
import semmle.python.objects.ObjectInternal
string vrepr(Value v) {
@@ -8,6 +9,6 @@ string vrepr(Value v) {
v = ObjectInternal::boundMethod() and result = "builtin-class method"
}
from ControlFlowNode f, Context ctx, Value v, ControlFlowNode origin
from ControlFlowNodeWithPointsTo f, Context ctx, Value v, ControlFlowNode origin
where f.pointsTo(ctx, v, origin)
select f.getLocation(), f.toString(), ctx, vrepr(v), vrepr(v.getClass())

View File

@@ -1,6 +1,7 @@
import python
private import LegacyPointsTo
from ControlFlowNode arg, CallNode call, string debug
from ControlFlowNodeWithPointsTo arg, CallNode call, string debug
where
call.getAnArg() = arg and
call.getFunction().(NameNode).getId() = "check" and

View File

@@ -1,6 +1,7 @@
import python
private import LegacyPointsTo
from ControlFlowNode arg, CallNode call, string debug
from ControlFlowNodeWithPointsTo arg, CallNode call, string debug
where
call.getAnArg() = arg and
call.getFunction().(NameNode).getId() = "check" and

View File

@@ -1,6 +1,7 @@
import python
private import LegacyPointsTo
from ControlFlowNode arg, CallNode call, string debug
from ControlFlowNodeWithPointsTo arg, CallNode call, string debug
where
call.getAnArg() = arg and
call.getFunction().(NameNode).getId() = "check" and

View File

@@ -1,10 +1,11 @@
import python
private import LegacyPointsTo
from NameNode name, CallNode call, string debug
where
call.getAnArg() = name and
call.getFunction().(NameNode).getId() = "check" and
if exists(name.pointsTo())
then debug = name.pointsTo().toString()
if exists(name.(ControlFlowNodeWithPointsTo).pointsTo())
then debug = name.(ControlFlowNodeWithPointsTo).pointsTo().toString()
else debug = "<MISSING pointsTo()>"
select name, debug

View File

@@ -1,11 +1,12 @@
import python
private import LegacyPointsTo
import semmle.python.pointsto.PointsTo
import semmle.python.pointsto.PointsToContext
import semmle.python.objects.ObjectInternal
from CallNode call, SuperInstance sup, BoundMethodObjectInternal bm
where
call.getFunction().inferredValue() = bm and
call.getFunction().(AttrNode).getObject().inferredValue() = sup
call.getFunction().(ControlFlowNodeWithPointsTo).inferredValue() = bm and
call.getFunction().(AttrNode).getObject().(ControlFlowNodeWithPointsTo).inferredValue() = sup
select call.getLocation().getStartLine(), call.toString(),
bm.getFunction().getSource().(FunctionObject).getQualifiedName()