mirror of
https://github.com/github/codeql.git
synced 2026-05-05 13:45:19 +02:00
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:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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, _)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user