mirror of
https://github.com/github/codeql.git
synced 2026-05-02 12:15:17 +02:00
Python points-to: Fix up test-evaluate for ABCs and tests involving type().
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
| builtin-class dict | builtin-class dict |
|
||||
| builtin-class dict | builtin-class list |
|
||||
| builtin-class int | (builtin-class float, builtin-class dict) |
|
||||
| builtin-class int | (builtin-class list, builtin-class int) |
|
||||
| builtin-class int | (builtin-class list, builtin-class int) |
|
||||
| builtin-class int | builtin-class dict |
|
||||
| builtin-class int | builtin-class float |
|
||||
| builtin-class int | builtin-class int |
|
||||
| builtin-class int | builtin-class list |
|
||||
| builtin-class int | builtin-class object |
|
||||
| builtin-class int | builtin-class tuple |
|
||||
| builtin-class tuple | builtin-class int |
|
||||
| builtin-class tuple | builtin-class tuple |
|
||||
8
python/ql/test/library-tests/PointsTo/subclass/Checks.ql
Normal file
8
python/ql/test/library-tests/PointsTo/subclass/Checks.ql
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
import python
|
||||
import semmle.python.pointsto.PointsTo
|
||||
import semmle.python.pointsto.PointsTo
|
||||
|
||||
from Value sup, Value cls
|
||||
where Expressions::requireSubClass(cls, sup)
|
||||
select cls, sup
|
||||
@@ -0,0 +1,11 @@
|
||||
| 3 | isinstance() | true | x | int 7 |
|
||||
| 4 | issubclass() | true | x | int 7 |
|
||||
| 6 | issubclass() | true | d | builtin-class dict |
|
||||
| 7 | UnaryExpr | true | d | builtin-class dict |
|
||||
| 10 | isinstance() | false | x | int 0 |
|
||||
| 10 | isinstance() | true | x | () |
|
||||
| 13 | isinstance() | false | x | () |
|
||||
| 13 | isinstance() | true | x | int 0 |
|
||||
| 14 | isinstance() | true | x | int 0 |
|
||||
| 15 | issubclass() | true | x | int 0 |
|
||||
| 16 | issubclass() | false | x | int 0 |
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
import python
|
||||
import semmle.python.pointsto.PointsTo
|
||||
import semmle.python.objects.ObjectInternal
|
||||
import semmle.python.pointsto.PointsToContext
|
||||
|
||||
|
||||
from ControlFlowNode test, ControlFlowNode use, ObjectInternal val, boolean eval, PointsToContext ctx
|
||||
where
|
||||
PointsTo::pointsTo(use, ctx, val, _) and
|
||||
eval = Conditionals::testEvaluates(test, use, ctx, val, _)
|
||||
select test.getLocation().getStartLine(), test.getNode().toString(), eval.toString(), use.getNode().toString(), val.toString()
|
||||
@@ -0,0 +1,66 @@
|
||||
| 2 | ControlFlowNode for IntegerLiteral | int 7 | 2 |
|
||||
| 3 | ControlFlowNode for int | builtin-class int | 3 |
|
||||
| 3 | ControlFlowNode for isinstance | Builtin-function isinstance | 3 |
|
||||
| 3 | ControlFlowNode for isinstance() | bool True | 3 |
|
||||
| 3 | ControlFlowNode for x | int 7 | 2 |
|
||||
| 4 | ControlFlowNode for issubclass | Builtin-function issubclass | 4 |
|
||||
| 4 | ControlFlowNode for issubclass() | bool True | 4 |
|
||||
| 4 | ControlFlowNode for object | builtin-class object | 4 |
|
||||
| 4 | ControlFlowNode for type | builtin-class type | 4 |
|
||||
| 4 | ControlFlowNode for type() | builtin-class int | 4 |
|
||||
| 4 | ControlFlowNode for x | int 7 | 2 |
|
||||
| 5 | ControlFlowNode for dict | builtin-class dict | 5 |
|
||||
| 6 | ControlFlowNode for d | builtin-class dict | 5 |
|
||||
| 6 | ControlFlowNode for dict | builtin-class dict | 6 |
|
||||
| 6 | ControlFlowNode for issubclass | Builtin-function issubclass | 6 |
|
||||
| 6 | ControlFlowNode for issubclass() | bool True | 6 |
|
||||
| 7 | ControlFlowNode for UnaryExpr | bool True | 7 |
|
||||
| 7 | ControlFlowNode for d | builtin-class dict | 5 |
|
||||
| 7 | ControlFlowNode for issubclass | Builtin-function issubclass | 7 |
|
||||
| 7 | ControlFlowNode for issubclass() | bool False | 7 |
|
||||
| 7 | ControlFlowNode for list | builtin-class list | 7 |
|
||||
| 9 | ControlFlowNode for IfExp | () | 9 |
|
||||
| 9 | ControlFlowNode for IfExp | int 0 | 9 |
|
||||
| 9 | ControlFlowNode for IntegerLiteral | int 0 | 9 |
|
||||
| 9 | ControlFlowNode for Tuple | () | 9 |
|
||||
| 9 | ControlFlowNode for condition | Unknown value | 9 |
|
||||
| 10 | ControlFlowNode for isinstance | Builtin-function isinstance | 10 |
|
||||
| 10 | ControlFlowNode for isinstance() | bool False | 10 |
|
||||
| 10 | ControlFlowNode for isinstance() | bool True | 10 |
|
||||
| 10 | ControlFlowNode for tuple | builtin-class tuple | 10 |
|
||||
| 10 | ControlFlowNode for x | () | 9 |
|
||||
| 10 | ControlFlowNode for x | int 0 | 9 |
|
||||
| 12 | ControlFlowNode for IntegerLiteral | int 3 | 12 |
|
||||
| 12 | ControlFlowNode for isinstance | Builtin-function isinstance | 12 |
|
||||
| 12 | ControlFlowNode for isinstance() | bool False | 12 |
|
||||
| 12 | ControlFlowNode for isinstance() | bool True | 12 |
|
||||
| 12 | ControlFlowNode for unknown | Unknown value | 12 |
|
||||
| 12 | ControlFlowNode for unknown() | Unknown value | 12 |
|
||||
| 13 | ControlFlowNode for int | builtin-class int | 13 |
|
||||
| 13 | ControlFlowNode for isinstance | Builtin-function isinstance | 13 |
|
||||
| 13 | ControlFlowNode for isinstance() | bool False | 13 |
|
||||
| 13 | ControlFlowNode for isinstance() | bool True | 13 |
|
||||
| 13 | ControlFlowNode for x | () | 9 |
|
||||
| 13 | ControlFlowNode for x | int 0 | 9 |
|
||||
| 14 | ControlFlowNode for Tuple | (builtin-class list, builtin-class int) | 14 |
|
||||
| 14 | ControlFlowNode for int | builtin-class int | 14 |
|
||||
| 14 | ControlFlowNode for isinstance | Builtin-function isinstance | 14 |
|
||||
| 14 | ControlFlowNode for isinstance() | bool True | 14 |
|
||||
| 14 | ControlFlowNode for list | builtin-class list | 14 |
|
||||
| 14 | ControlFlowNode for x | int 0 | 9 |
|
||||
| 15 | ControlFlowNode for Tuple | (builtin-class list, builtin-class int) | 15 |
|
||||
| 15 | ControlFlowNode for int | builtin-class int | 15 |
|
||||
| 15 | ControlFlowNode for issubclass | Builtin-function issubclass | 15 |
|
||||
| 15 | ControlFlowNode for issubclass() | bool True | 15 |
|
||||
| 15 | ControlFlowNode for list | builtin-class list | 15 |
|
||||
| 15 | ControlFlowNode for type | builtin-class type | 15 |
|
||||
| 15 | ControlFlowNode for type() | builtin-class int | 15 |
|
||||
| 15 | ControlFlowNode for x | int 0 | 9 |
|
||||
| 16 | ControlFlowNode for Tuple | (builtin-class float, builtin-class dict) | 16 |
|
||||
| 16 | ControlFlowNode for dict | builtin-class dict | 16 |
|
||||
| 16 | ControlFlowNode for float | builtin-class float | 16 |
|
||||
| 16 | ControlFlowNode for issubclass | Builtin-function issubclass | 16 |
|
||||
| 16 | ControlFlowNode for issubclass() | bool False | 16 |
|
||||
| 16 | ControlFlowNode for type | builtin-class type | 16 |
|
||||
| 16 | ControlFlowNode for type() | builtin-class int | 16 |
|
||||
| 16 | ControlFlowNode for x | int 0 | 9 |
|
||||
10
python/ql/test/library-tests/PointsTo/subclass/Values.ql
Normal file
10
python/ql/test/library-tests/PointsTo/subclass/Values.ql
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
import python
|
||||
import semmle.python.pointsto.PointsTo
|
||||
import semmle.python.objects.ObjectInternal
|
||||
|
||||
from ControlFlowNode f, ObjectInternal v, ControlFlowNode x
|
||||
|
||||
where PointsTo::pointsTo(f, _, v, x)
|
||||
|
||||
select f.getLocation().getStartLine(), f.toString(), v, x.getLocation().getStartLine()
|
||||
18
python/ql/test/library-tests/PointsTo/subclass/test.py
Normal file
18
python/ql/test/library-tests/PointsTo/subclass/test.py
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
x = 7
|
||||
assert isinstance(x, int)
|
||||
assert issubclass(type(x), object)
|
||||
d = dict
|
||||
assert issubclass(d, dict)
|
||||
assert not issubclass(d, list)
|
||||
|
||||
x = 0 if condition else ()
|
||||
if isinstance(x, tuple):
|
||||
pass
|
||||
isinstance(3, unknown())
|
||||
assert isinstance(x, int)
|
||||
assert isinstance(x, (list, int))
|
||||
assert issubclass(type(x), (list, int))
|
||||
if issubclass(type(x), (float, dict)):
|
||||
pass
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
import python
|
||||
import semmle.python.pointsto.PointsTo
|
||||
import semmle.python.pointsto.PointsToContext
|
||||
import semmle.python.objects.ObjectInternal
|
||||
|
||||
from CallNode call, FunctionObject method
|
||||
where PointsTo::Test::super_method_call(_, call, _, method)
|
||||
select call.getLocation().getStartLine(), call.toString(), method.getQualifiedName()
|
||||
|
||||
from CallNode call, SuperInstance sup, BoundMethodObjectInternal bm
|
||||
where call.getFunction().inferredValue() = bm and
|
||||
call.getFunction().(AttrNode).getObject().inferredValue() = sup
|
||||
select call.getLocation().getStartLine(), call.toString(), bm.getFunction().getSource().(FunctionObject).getQualifiedName()
|
||||
@@ -2,8 +2,8 @@
|
||||
import python
|
||||
import semmle.python.pointsto.MRO
|
||||
|
||||
from ClassObject cls
|
||||
from ClassValue cls
|
||||
where not cls.isBuiltin()
|
||||
|
||||
select cls.toString(), new_style_mro(cls)
|
||||
select cls.toString(), Mro::newStyleMro(cls)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user