Remove redundant tests.

This commit is contained in:
Mark Shannon
2019-04-17 13:04:35 +01:00
parent 4145b19671
commit 2aa967ae8e
8 changed files with 32 additions and 58 deletions

View File

@@ -1705,16 +1705,10 @@ cached module Types {
or
exists(cls.(PythonClassObjectInternal).getScope().getADecorator()) and not six_add_metaclass(_, cls, _) and reason = "Decorator not understood"
or
exists(int i |
exists(cls.(PythonClassObjectInternal).getScope().getBase(i)) and reason = "Missing base " + i
|
not exists(getBase(cls, i))
)
reason = "Missing base " + missingBase(cls)
or
exists(cls.(PythonClassObjectInternal).getScope().getMetaClass()) and not exists(cls.getClass()) and reason = "Failed to infer metaclass"
or
exists(int i | failedInference(getBase(cls, i), _) and reason = "Failed inference for base class at position " + i)
or
exists(int i, ObjectInternal base1, ObjectInternal base2 |
base1 = getBase(cls, i) and
base2 = getBase(cls, i) and
@@ -1722,7 +1716,24 @@ cached module Types {
reason = "Multiple bases at position " + i
)
or
exists(int i, int j | getBase(cls, i) = getBase(cls, j) and i != j and reason = "Duplicate bases classes")
duplicateBase(cls) and reason = "Duplicate bases classes"
or
not exists(getMro(cls)) and reason = "Failed to compute MRO" and not exists(missingBase(cls)) and not duplicateBase(cls)
or
exists(int i | failedInference(getBase(cls, i), _) and reason = "Failed inference for base class at position " + i)
}
private int missingBase(ClassObjectInternal cls) {
exists(cls.(PythonClassObjectInternal).getScope().getBase(result))
and
not exists(getBase(cls, result)) or getBase(cls, result) = ObjectInternal::unknownClass()
}
private predicate duplicateBase(ClassObjectInternal cls) {
exists(int i, int j, ClassObjectInternal dup |
dup = getBase(cls, i) and dup != ObjectInternal::unknownClass() and
dup = getBase(cls, j) and i != j
)
}
cached boolean improperSubclass(ObjectInternal sub, ObjectInternal sup) {

View File

@@ -1204,11 +1204,10 @@ library module TaintFlowImplementation {
exists(ParameterDefinition def |
def.getDefiningNode() = param and
exists(CallableValue func, CallNode call |
call.getFunction().pointsTo() = func and
callee = caller.getCallee(call) |
exists(int n | param = func.getParameter(n) and argument = call.getArg(n))
exists(int n | param = func.getParameter(n) and argument = func.getArgumentForCall(call, n))
or
exists(string name | param = func.getParameterByName(name) and argument = call.getArgByName(name))
exists(string name | param = func.getParameterByName(name) and argument = func.getNamedArgumentForCall(call, name))
or
class_initializer_argument(_, _, call, func, argument, param)
)

View File

@@ -1,9 +0,0 @@
| test.py:10 ... fail
| test.py:11:5:11:7 | ControlFlowNode for Attribute | bound method 'm' of instance of C | test.py:11:5:11:7 | ControlFlowNode for Attribute |
| test.py:12:5:12:10 | ControlFlowNode for Attribute() | 3 | test.py:12:9:12:9 | ControlFlowNode for IntegerLiteral |
| test.py:16:5:16:5 | ControlFlowNode for t | bound method 'm' of instance of C | test.py:15:9:15:11 | ControlFlowNode for Attribute |
| test.py:17:5:17:8 | ControlFlowNode for t() | 4 | test.py:17:7:17:7 | ControlFlowNode for IntegerLiteral |
| test.py:24:1:24:1 | ControlFlowNode for D | class D | test.py:19:1:19:16 | ControlFlowNode for ClassExpr |
| test.py:25 ... fail
| test.py:26 ... fail
| test.py:27 ... fail

View File

@@ -1,10 +0,0 @@
import python
import semmle.python.pointsto.PointsTo2
import semmle.python.objects.ObjectInternal
from ControlFlowNode f, ObjectInternal obj, ControlFlowNode orig
where exists(ExprStmt s | s.getValue().getAFlowNode() = f) and
PointsTo2::points_to(f, _, obj, orig)
select f, obj.toString(), orig

View File

@@ -1,27 +0,0 @@
class C(object):
def m(self, arg1):
return arg1
c = C()
def func_and_method():
C.m
c.m
c.m(3)
def flow_bound_method():
t = c.m
t
t(4)
class D(object):
@staticmethod
def foo(arg):
return arg
D
D.foo
D.foo(1)
D().foo(2)

View File

@@ -0,0 +1 @@
fail

View File

@@ -0,0 +1,9 @@
import python
import Util
from ControlFlowNode f, Context ctx, Value v, ControlFlowNode origin
where
f.pointsTo(ctx, v, origin)
select locate(f.getLocation(), "c"), f.toString(), ctx, v, v.getClass()

View File

@@ -3,7 +3,7 @@ import semmle.python.security.TaintTest
import TaintLib
from ModuleObject m, string name, TaintedNode origin
from ModuleValue m, string name, TaintedNode origin
where TaintFlowTest::module_attribute_tainted(m, name, origin)