mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +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:
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
import analysis.DefinitionTracking
|
||||
|
||||
predicate uniqueness_error(int number, string what, string problem) {
|
||||
@@ -208,18 +209,22 @@ predicate function_object_consistency(string clsname, string problem, string wha
|
||||
predicate multiple_origins_per_object(Object obj) {
|
||||
not obj.isC() and
|
||||
not obj instanceof ModuleObject and
|
||||
exists(ControlFlowNode use, Context ctx |
|
||||
exists(ControlFlowNodeWithPointsTo use, Context ctx |
|
||||
strictcount(ControlFlowNode orig | use.refersTo(ctx, obj, _, orig)) > 1
|
||||
)
|
||||
}
|
||||
|
||||
predicate intermediate_origins(ControlFlowNode use, ControlFlowNode inter, Object obj) {
|
||||
predicate intermediate_origins(
|
||||
ControlFlowNodeWithPointsTo use, ControlFlowNodeWithPointsTo inter, Object obj
|
||||
) {
|
||||
exists(ControlFlowNode orig, Context ctx | not inter = orig |
|
||||
use.refersTo(ctx, obj, _, inter) and
|
||||
inter.refersTo(ctx, obj, _, orig) and
|
||||
// It can sometimes happen that two different modules (e.g. cPickle and Pickle)
|
||||
// have the same attribute, but different origins.
|
||||
not strictcount(Object val | inter.(AttrNode).getObject().refersTo(val)) > 1
|
||||
not strictcount(Object val |
|
||||
inter.(AttrNode).getObject().(ControlFlowNodeWithPointsTo).refersTo(val)
|
||||
) > 1
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
import semmle.python.pointsto.PointsTo
|
||||
import semmle.python.pointsto.PointsToContext
|
||||
|
||||
@@ -18,11 +19,11 @@ predicate trivial(ControlFlowNode f) {
|
||||
from int interesting_facts, int interesting_facts_in_source, int total_size, float efficiency
|
||||
where
|
||||
interesting_facts =
|
||||
strictcount(ControlFlowNode f, Object value, ClassObject cls |
|
||||
strictcount(ControlFlowNodeWithPointsTo f, Object value, ClassObject cls |
|
||||
f.refersTo(value, cls, _) and not trivial(f)
|
||||
) and
|
||||
interesting_facts_in_source =
|
||||
strictcount(ControlFlowNode f, Object value, ClassObject cls |
|
||||
strictcount(ControlFlowNodeWithPointsTo f, Object value, ClassObject cls |
|
||||
f.refersTo(value, cls, _) and
|
||||
not trivial(f) and
|
||||
exists(f.getScope().getEnclosingModule().getFile().getRelativePath())
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
ImportExpr alternative_import(ImportExpr ie) {
|
||||
exists(Alias thisalias, Alias otheralias |
|
||||
@@ -62,7 +63,10 @@ class VersionTest extends ControlFlowNode {
|
||||
VersionTest() {
|
||||
exists(string name |
|
||||
name.matches("%version%") and
|
||||
this.(CompareNode).getAChild+().pointsTo(Module::named("sys").attr(name))
|
||||
this.(CompareNode)
|
||||
.getAChild+()
|
||||
.(ControlFlowNodeWithPointsTo)
|
||||
.pointsTo(Module::named("sys").attr(name))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Expr e
|
||||
where exists(ControlFlowNode f | f = e.getAFlowNode() | not f.refersTo(_))
|
||||
where exists(ControlFlowNodeWithPointsTo f | f = e.getAFlowNode() | not f.refersTo(_))
|
||||
select e, "Expression does not 'point-to' any object."
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from ControlFlowNode f, Object o
|
||||
from ControlFlowNodeWithPointsTo f, Object o
|
||||
where
|
||||
f.refersTo(o) and
|
||||
not f.refersTo(o, _, _)
|
||||
|
||||
Reference in New Issue
Block a user