Merge branch 'master' into python-objectapi-to-valueapi-returnvalueignored

This commit is contained in:
Rebecca Valentine
2020-04-01 07:37:17 -07:00
1188 changed files with 47855 additions and 38746 deletions

View File

@@ -1,6 +1,5 @@
import python
from ExceptFlowNode ex, Object obj
where ex.handledException(obj, _, _)
select ex.getLocation().getStartLine(), ex.toString(), obj.toString()
from ExceptFlowNode ex, Value val
where ex.handledException(val, _, _)
select ex.getLocation().getStartLine(), ex.toString(), val.toString()

View File

@@ -1,5 +1,4 @@
import python
from RaisingNode r
select r.getLocation().getStartLine(), r.toString(), r.getARaisedType().toString()
select r.getLocation().getStartLine(), r.toString(), r.getARaisedType().toString()

View File

@@ -1,7 +1,7 @@
import python
from ControlFlowNode r, ControlFlowNode s
where s = r.getAnExceptionalSuccessor() and
not r.(RaisingNode).unlikelySuccessor(s)
select r.getLocation().getStartLine(), r.toString(), s.getLocation().getStartLine(), s.toString()
where
s = r.getAnExceptionalSuccessor() and
not r.(RaisingNode).unlikelySuccessor(s)
select r.getLocation().getStartLine(), r.toString(), s.getLocation().getStartLine(), s.toString()

View File

@@ -1,6 +1,5 @@
import python
from RaisingNode r
where r.raisesUnknownType()
select r.getLocation().getStartLine(), r.toString()
select r.getLocation().getStartLine(), r.toString()

View File

@@ -1,11 +1,12 @@
import python
import semmle.python.pointsto.PointsTo
import semmle.python.pointsto.PointsToContext
from ControlFlowNode f, Location l, Context c
where not PointsToInternal::reachableBlock(f.getBasicBlock(), c) and c.isImport() and
(f.getNode() instanceof FunctionExpr or f.getNode() instanceof ClassExpr) and
l = f.getLocation() and l.getFile().getShortName() = "test.py"
where
not PointsToInternal::reachableBlock(f.getBasicBlock(), c) and
c.isImport() and
(f.getNode() instanceof FunctionExpr or f.getNode() instanceof ClassExpr) and
l = f.getLocation() and
l.getFile().getShortName() = "test.py"
select l.getStartLine()

View File

@@ -1,9 +1,10 @@
import python
from int line, ControlFlowNode f, Object o, ControlFlowNode orig
where
not f.getLocation().getFile().inStdlib() and
f.refersTo(o, orig) and line = f.getLocation().getStartLine() and line != 0 and
not o instanceof NumericObject // Omit sys.hexversion as it will change between machines
where
not f.getLocation().getFile().inStdlib() and
f.refersTo(o, orig) and
line = f.getLocation().getStartLine() and
line != 0 and
not o instanceof NumericObject // Omit sys.hexversion as it will change between machines
select f.getLocation().getFile().getShortName(), line, f.toString(), o.toString(), orig.toString()

View File

@@ -1,4 +1,3 @@
import python
from ClassObject cls

View File

@@ -1,14 +1,11 @@
import python
string short_loc(Location l) {
result = l.getFile().getShortName() + ":" + l.getStartLine()
}
string short_loc(Location l) { result = l.getFile().getShortName() + ":" + l.getStartLine() }
from ControlFlowNode use, Object obj, ControlFlowNode orig, int line
where use.refersTo(obj, orig) and
use.getLocation().getFile().getShortName() = "test.py" and
line = use.getLocation().getStartLine() and
not line = 0
where
use.refersTo(obj, orig) and
use.getLocation().getFile().getShortName() = "test.py" and
line = use.getLocation().getStartLine() and
not line = 0
select line, use.toString(), obj.toString(), short_loc(orig.getLocation())

View File

@@ -7,7 +7,9 @@
import python
from ClassObject cls, int line, string name, Object obj
where cls.hasLocationInfo(_, line, _, _, _)
and obj = cls.lookupAttribute(name) and
not cls.isC() and not name.matches("\\_\\_%\\_\\_")
select line, cls.toString(), name, obj.toString()
where
cls.hasLocationInfo(_, line, _, _, _) and
obj = cls.lookupAttribute(name) and
not cls.isC() and
not name.matches("\\_\\_%\\_\\_")
select line, cls.toString(), name, obj.toString()

View File

@@ -7,7 +7,9 @@
import python
from ClassObject cls, int line, string name
where cls.hasLocationInfo(_, line, _, _, _)
and cls.hasAttribute(name) and
not cls.isC() and not name.matches("\\_\\_%\\_\\_")
where
cls.hasLocationInfo(_, line, _, _, _) and
cls.hasAttribute(name) and
not cls.isC() and
not name.matches("\\_\\_%\\_\\_")
select line, cls.toString(), name

View File

@@ -7,10 +7,10 @@
import python
from ClassObject cls, string name, Object what
where
(cls.getName() = "list" or
cls.getASuperType().getName() = "list"
)
and
cls.lookupAttribute(name) = what
where
(
cls.getName() = "list" or
cls.getASuperType().getName() = "list"
) and
cls.lookupAttribute(name) = what
select cls.toString(), name, what.toString()

View File

@@ -1,18 +1,12 @@
import python
import semmle.python.pointsto.MRO
import semmle.python.pointsto.PointsTo
import semmle.python.objects.ObjectInternal
ClassList mro(ClassObjectInternal cls) {
if Types::isNewStyle(cls) then
result = Mro::newStyleMro(cls)
else
result = Mro::oldStyleMro(cls)
if Types::isNewStyle(cls) then result = Mro::newStyleMro(cls) else result = Mro::oldStyleMro(cls)
}
from ClassObjectInternal cls
where not cls.isBuiltin()
select cls.toString(), mro(cls)

View File

@@ -1,8 +1,7 @@
import python
from ClassObject cls, ClassObject l, ClassObject r
where not cls.isC() and
r = cls.nextInMro(l)
where
not cls.isC() and
r = cls.nextInMro(l)
select cls.toString(), l.toString(), r.toString()

View File

@@ -4,4 +4,6 @@
import python
select count(Comprehension c | count(c.toString()) != 1 or count(c.getLocation()) != 1 or not exists(c.getAFlowNode()))
select count(Comprehension c |
count(c.toString()) != 1 or count(c.getLocation()) != 1 or not exists(c.getAFlowNode())
)

View File

@@ -9,8 +9,7 @@ import python
from string classname
where
exists(AstNode node | not exists(node.getLocation()) and classname = node.getAQlClass())
or
exists(ControlFlowNode node | not exists(node.getLocation()) and classname = node.getAQlClass())
exists(AstNode node | not exists(node.getLocation()) and classname = node.getAQlClass())
or
exists(ControlFlowNode node | not exists(node.getLocation()) and classname = node.getAQlClass())
select classname

View File

@@ -1,6 +1,5 @@
import python
from AstNode ast, Location l
where ast.getLocation() = l
select ast.getAQlClass(), l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn()
select ast.getAQlClass(), l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn()

View File

@@ -1,5 +1,4 @@
import python
from StrConst s
select s.getLocation().getStartLine(), s.getText(), s.getPrefix()
from StrConst s
select s.getLocation().getStartLine(), s.getText(), s.getPrefix()

View File

@@ -1,6 +1,5 @@
import python
from Keyword k, Location l
where k.getLocation() = l
select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn()
select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn()

View File

@@ -2,4 +2,4 @@ import python
from StrConst s, int bl, int bc, int el, int ec
where s.getLocation().hasLocationInfo(_, bl, bc, el, ec)
select bl, bc, el, ec, s.getText()
select bl, bc, el, ec, s.getText()

View File

@@ -1,7 +1,9 @@
import python
from ImportExpr ie, string m, string t, string r
where m = ie.getImportedModuleName() and
(if ie.isTop() then t = "top" else t = "bottom") and
(if ie.isRelative() then r= "relative" else r = "absolute")
select ie.getScope().toString(), ie.getLocation().getStartLine(), ie.toString(), ie.getLevel(), t, r, m
where
m = ie.getImportedModuleName() and
(if ie.isTop() then t = "top" else t = "bottom") and
(if ie.isRelative() then r = "relative" else r = "absolute")
select ie.getScope().toString(), ie.getLocation().getStartLine(), ie.toString(), ie.getLevel(), t,
r, m

View File

@@ -1,4 +1,3 @@
import python
from ModuleObject m, string name

View File

@@ -2,4 +2,4 @@ import python
from ModuleObject m, string name
where not m.isC() and m.importedAs(name)
select m.toString(), name
select m.toString(), name

View File

@@ -1,8 +1,6 @@
/* Test that there are no literals that do not have a corresponding object. */
import python
string repr(Expr e) {
result = e.(Num).getN() or
result = e.(Bytes).getS() or
@@ -10,7 +8,5 @@ string repr(Expr e) {
}
from ImmutableLiteral l
where
not exists(l.getLiteralObject())
select l.getLocation().getStartLine(), repr(l)
where not exists(l.getLiteralObject())
select l.getLocation().getStartLine(), repr(l)

View File

@@ -1,7 +1,5 @@
import python
from ClassObject cls
where not cls.isC()
select cls.toString(), cls.getMro()

View File

@@ -1,13 +1,8 @@
import python
from ClassObject cls, string style
where not cls.isC() and
not cls.failedInference() and
(
if cls.isNewStyle() then
style = "new"
else
style = "old"
)
where
not cls.isC() and
not cls.failedInference() and
(if cls.isNewStyle() then style = "new" else style = "old")
select cls.toString(), style

View File

@@ -2,5 +2,4 @@ import python
from RaisingNode r, Scope s, ClassObject cls
where r.viableExceptionalExit(s, cls)
select r.getLocation().getStartLine(), r.toString(), s.toString(), cls.toString()

View File

@@ -1,13 +1,12 @@
import python
from PyFunctionObject f, string type
where
where
type = f.getARaisedType().toString()
or
type = "Unknown" and f.raisesUnknownType()
or
not exists(f.getARaisedType()) and
not f.raisesUnknownType() and type = "None"
select f.toString(), type
not f.raisesUnknownType() and
type = "None"
select f.toString(), type

View File

@@ -1,4 +1,3 @@
import python
from FunctionObject func, ControlFlowNode call

View File

@@ -2,4 +2,4 @@ import python
from FunctionObject func
where func.neverReturns()
select func.getOrigin().getLocation().getStartLine(), func.getName()
select func.getOrigin().getLocation().getStartLine(), func.getName()

View File

@@ -21,4 +21,4 @@
| 112 | multi_return | builtin-class int |
| 118 | do_something | builtin-class int |
| 123 | with_flow | builtin-class int |
| 128 | return_default | builtin-class tuple |
| 128 | return_default | builtin-class tuple |

View File

@@ -1,7 +1,5 @@
import python
from PyFunctionObject func, ClassObject ret_type
where func.getAnInferredReturnType() = ret_type
select func.getOrigin().getLocation().getStartLine(), func.getName(), ret_type.toString()

View File

@@ -1,7 +1,8 @@
import python
from ClassObject cls, string name, BuiltinPropertyObject p
where cls.declaredAttribute(name) = p and
(cls = theObjectType() or cls = theListType() or cls = theTypeType())
select cls.toString(), name, p.toString(), p.getGetter().toString(), p.getSetter().toString(), p.getDeleter().toString()
where
cls.declaredAttribute(name) = p and
(cls = theObjectType() or cls = theListType() or cls = theTypeType())
select cls.toString(), name, p.toString(), p.getGetter().toString(), p.getSetter().toString(),
p.getDeleter().toString()

View File

@@ -1 +1 @@
| nonsense.py:1:14:1:14 | Syntax Error | Syntax Error (in Python 2.7). |
| nonsense.py:1:14:1:14 | Syntax Error | Syntax Error (in Python 2). |

View File

@@ -1,6 +1,5 @@
import python
from ExceptFlowNode ex, Object obj
where ex.handledException(obj, _, _)
select ex.getLocation().getStartLine(), ex.toString(), obj.toString()
from ExceptFlowNode ex, Value val
where ex.handledException(val, _, _)
select ex.getLocation().getStartLine(), ex.toString(), val.toString()

View File

@@ -1,5 +1,4 @@
import python
from RaisingNode r
select r.getLocation().getStartLine(), r.toString(), r.getARaisedType().toString()
select r.getLocation().getStartLine(), r.toString(), r.getARaisedType().toString()

View File

@@ -1,7 +1,7 @@
import python
from ControlFlowNode r, ControlFlowNode s
where s = r.getAnExceptionalSuccessor() and
not r.(RaisingNode).unlikelySuccessor(s)
select r.getLocation().getStartLine(), r.toString(), s.getLocation().getStartLine(), s.toString()
where
s = r.getAnExceptionalSuccessor() and
not r.(RaisingNode).unlikelySuccessor(s)
select r.getLocation().getStartLine(), r.toString(), s.getLocation().getStartLine(), s.toString()

View File

@@ -1,6 +1,5 @@
import python
from RaisingNode r
where r.raisesUnknownType()
select r.getLocation().getStartLine(), r.toString()
select r.getLocation().getStartLine(), r.toString()

View File

@@ -1,7 +1,5 @@
import python
from ControlFlowNode f, Object o, ControlFlowNode x
where f.refersTo(o, x)
select f.getLocation().getStartLine(), f.toString(), o.toString(), x.getLocation().getStartLine()

View File

@@ -1,7 +1,6 @@
import python
from ControlFlowNode f, Object o, ClassObject c, ControlFlowNode x
where f.refersTo(o, c, x)
select f.getLocation().getStartLine(), f.toString(), o.toString(), c.toString(), x.getLocation().getStartLine()
select f.getLocation().getStartLine(), f.toString(), o.toString(), c.toString(),
x.getLocation().getStartLine()

View File

@@ -1,5 +1,5 @@
WARNING: Predicate points_to has been deprecated and may be removed in future (BooleanConstants.ql:8,5-24)
WARNING: Predicate points_to has been deprecated and may be removed in future (BooleanConstants.ql:11,5-24)
WARNING: Predicate points_to has been deprecated and may be removed in future (BooleanConstants.ql:6,25-44)
WARNING: Predicate points_to has been deprecated and may be removed in future (BooleanConstants.ql:7,29-48)
| module.py | 2 | ControlFlowNode for ImportExpr | import | true |
| module.py | 2 | ControlFlowNode for sys | import | true |
| module.py | 3 | ControlFlowNode for Compare | import | false |

View File

@@ -2,13 +2,8 @@ import python
import semmle.python.pointsto.PointsTo
from ControlFlowNode f, Context c, boolean b
where
exists(Object obj |
PointsTo::points_to(f, c, obj, _, _) and obj.booleanValue() = b
) and
not exists(Object obj |
PointsTo::points_to(f, c, obj, _, _) and not obj.booleanValue() = b
)
select f.getLocation().getFile().getShortName(), f.getLocation().getStartLine(), f.toString(), c.toString(), b
where
exists(Object obj | PointsTo::points_to(f, c, obj, _, _) and obj.booleanValue() = b) and
not exists(Object obj | PointsTo::points_to(f, c, obj, _, _) and not obj.booleanValue() = b)
select f.getLocation().getFile().getShortName(), f.getLocation().getStartLine(), f.toString(),
c.toString(), b

View File

@@ -1,7 +1,9 @@
import python
import semmle.python.pointsto.PointsTo
from ControlFlowNode f, Location l
where not PointsToInternal::reachableBlock(f.getBasicBlock(), _) and l = f.getLocation() and l.getFile().getShortName() = "test.py"
where
not PointsToInternal::reachableBlock(f.getBasicBlock(), _) and
l = f.getLocation() and
l.getFile().getShortName() = "test.py"
select l.getStartLine()

View File

@@ -1,8 +1,5 @@
import python
from Call c, FunctionObject f
where f.getACall().getNode() = c
select c.getLocation().getStartLine(), f.toString(), f.getFunction().getLocation().getStartLine()

View File

@@ -1,4 +1,3 @@
import python
from ClassObject cls

View File

@@ -0,0 +1,3 @@
| mwe_failure.py:7:1:7:23 | class MyTest | <MISSING BASE TYPE> |
| mwe_failure_2.py:7:1:7:23 | class MyTest | <MISSING BASE TYPE> |
| mwe_success.py:7:1:7:23 | class MyTest | class TestCase |

View File

@@ -0,0 +1,11 @@
import python
// as used in semmle.python.filters.Tests
from ClassValue c, string base
where
c.getScope().getLocation().getFile().getShortName().matches("mwe%.py") and
c.getName() = "MyTest" and
if exists(c.getABaseType())
then base = c.getABaseType().toString()
else base = "<MISSING BASE TYPE>"
select c, base

View File

@@ -0,0 +1,10 @@
import subprocess
assert subprocess.call(['run-backup']) == 0
class TestCase:
pass
class MyTest(TestCase):
pass
# found by /home/rasmus/code/ql/python/ql/test/query-tests/Statements/asserts/AssertLiteralConstant.qlref

View File

@@ -0,0 +1,8 @@
import subprocess
assert subprocess.call(['run-backup'])
class TestCase:
pass
class MyTest(TestCase):
pass

View File

@@ -0,0 +1,8 @@
import subprocess
subprocess.call(['run-backup'])
class TestCase:
pass
class MyTest(TestCase):
pass

View File

@@ -0,0 +1 @@
semmle-extractor-options: --lang=3 --max-import-depth=1

View File

@@ -1,8 +1,7 @@
import python
from ControlFlowNode f, Context ctx, Value v, ControlFlowNode origin
where
f.pointsTo(ctx, v, origin) and
f.getLocation().getFile().getBaseName() = "test.py"
f.pointsTo(ctx, v, origin) and
f.getLocation().getFile().getBaseName() = "test.py"
select f.getLocation(), f.toString(), ctx, v

View File

@@ -7,7 +7,9 @@
import python
from ClassObject cls, int line, string name, Object obj
where cls.hasLocationInfo(_, line, _, _, _)
and obj = cls.lookupAttribute(name) and
not cls.isC() and not name.matches("\\_\\_%\\_\\_")
select line, cls.toString(), name, obj.toString()
where
cls.hasLocationInfo(_, line, _, _, _) and
obj = cls.lookupAttribute(name) and
not cls.isC() and
not name.matches("\\_\\_%\\_\\_")
select line, cls.toString(), name, obj.toString()

View File

@@ -7,7 +7,9 @@
import python
from ClassObject cls, int line, string name
where cls.hasLocationInfo(_, line, _, _, _)
and cls.hasAttribute(name) and
not cls.isC() and not name.matches("\\_\\_%\\_\\_")
where
cls.hasLocationInfo(_, line, _, _, _) and
cls.hasAttribute(name) and
not cls.isC() and
not name.matches("\\_\\_%\\_\\_")
select line, cls.toString(), name

View File

@@ -1,4 +1,4 @@
import python
from ClassExpr cls
select cls.toString(), cls.getMetaClass().toString()
select cls.toString(), cls.getMetaClass().toString()

View File

@@ -2,4 +2,4 @@ import python
from ClassObject cls
where not cls.isC()
select cls.toString(), cls.getAnInferredType().toString()
select cls.toString(), cls.getAnInferredType().toString()

View File

@@ -7,6 +7,7 @@
import python
from ClassObject cls, ClassObject l, ClassObject r
where not cls.isC() and
r = cls.nextInMro(l)
where
not cls.isC() and
r = cls.nextInMro(l)
select cls.toString(), l.toString(), r.toString()

View File

@@ -7,6 +7,7 @@
import python
from ClassObject cls, ClassObject sup, int index
where sup = cls.getMroItem(index) and
not cls.isC()
where
sup = cls.getMroItem(index) and
not cls.isC()
select cls.toString(), index, sup.toString()

View File

@@ -1,6 +1,5 @@
import python
from AstNode a, Location l
where a.getLocation() = l
select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn(), a.toString()
select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn(), a.toString()

View File

@@ -9,8 +9,7 @@ import python
from string classname
where
exists(AstNode node | not exists(node.getLocation()) and classname = node.getAQlClass())
or
exists(ControlFlowNode node | not exists(node.getLocation()) and classname = node.getAQlClass())
exists(AstNode node | not exists(node.getLocation()) and classname = node.getAQlClass())
or
exists(ControlFlowNode node | not exists(node.getLocation()) and classname = node.getAQlClass())
select classname

View File

@@ -1,6 +1,5 @@
import python
from AstNode ast, Location l
where ast.getLocation() = l
select ast.getAQlClass(), l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn()
select ast.getAQlClass(), l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn()

View File

@@ -1,5 +1,4 @@
import python
from StrConst s
select s.getLocation().getStartLine(), s.getText(), s.getPrefix()
from StrConst s
select s.getLocation().getStartLine(), s.getText(), s.getPrefix()

View File

@@ -1,6 +1,5 @@
import python
from Keyword k, Location l
where k.getLocation() = l
select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn()
select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn()

View File

@@ -1,7 +1,9 @@
import python
from ImportExpr ie, string m, string t, string r
where m = ie.getImportedModuleName() and
(if ie.isTop() then t = "top" else t = "bottom") and
(if ie.isRelative() then r= "relative" else r = "absolute")
select ie.getScope().toString(), ie.getLocation().getStartLine(), ie.toString(), ie.getLevel(), t, r, m
where
m = ie.getImportedModuleName() and
(if ie.isTop() then t = "top" else t = "bottom") and
(if ie.isRelative() then r = "relative" else r = "absolute")
select ie.getScope().toString(), ie.getLocation().getStartLine(), ie.toString(), ie.getLevel(), t,
r, m

View File

@@ -1,4 +1,3 @@
import python
from ModuleObject m, string name

View File

@@ -1,9 +1,9 @@
| test.py:11 | extended_unpacking | first | NO TAINT |
| test.py:11 | extended_unpacking | last | NO TAINT |
| test.py:11 | extended_unpacking | rest | NO TAINT |
| test.py:16 | also_allowed | a | NO TAINT |
| test.py:11 | extended_unpacking | first | externally controlled string |
| test.py:11 | extended_unpacking | last | externally controlled string |
| test.py:11 | extended_unpacking | rest | [externally controlled string] |
| test.py:16 | also_allowed | a | [externally controlled string] |
| test.py:24 | also_allowed | b | NO TAINT |
| test.py:24 | also_allowed | c | NO TAINT |
| test.py:31 | nested | x | NO TAINT |
| test.py:31 | nested | xs | NO TAINT |
| test.py:31 | nested | ys | NO TAINT |
| test.py:31 | nested | x | externally controlled string |
| test.py:31 | nested | xs | [externally controlled string] |
| test.py:31 | nested | ys | [externally controlled string] |

View File

@@ -15,4 +15,5 @@ where
taint_string = tainted.getTaintKind().toString()
)
)
select arg.getLocation().toString(), call.getScope().(Function).getName(), arg.toString(), taint_string
select arg.getLocation().toString(), call.getScope().(Function).getName(), arg.toString(),
taint_string

View File

@@ -1,7 +1,5 @@
import python
from ClassObject cls, ClassObject sup
where not cls.isC()
select cls.toString(), sup.toString(), cls.nextInMro(sup).toString()

View File

@@ -1,13 +1,12 @@
import python
from PyFunctionObject f, string type
where
where
type = f.getARaisedType().toString()
or
type = "Unknown" and f.raisesUnknownType()
or
not exists(f.getARaisedType()) and
not f.raisesUnknownType() and type = "None"
select f.toString(), type
not f.raisesUnknownType() and
type = "None"
select f.toString(), type

View File

@@ -1,7 +1,6 @@
import python
from RaisingNode r, ControlFlowNode n, ClassObject ex
where r.viableExceptionEdge(n, ex)
select r.getLocation().getStartLine(), n.getLocation().getStartLine(), r.getNode().toString(), n.getNode().toString(), ex.toString()
select r.getLocation().getStartLine(), n.getLocation().getStartLine(), r.getNode().toString(),
n.getNode().toString(), ex.toString()

View File

@@ -1,7 +1,5 @@
import python
from FunctionObject func, ControlFlowNode call
where func.getACall() = call
select call.getLocation().getStartLine(), call.toString(), func.toString()

View File

@@ -2,4 +2,4 @@ import python
from FunctionObject func
where func.neverReturns()
select func.getOrigin().getLocation().getStartLine(), func.getName()
select func.getOrigin().getLocation().getStartLine(), func.getName()

View File

@@ -1,7 +1,5 @@
import python
from PyFunctionObject func, ClassObject ret_type
where func.getAnInferredReturnType() = ret_type
select func.getOrigin().getLocation().getStartLine(), func.getName(), ret_type.toString()

View File

@@ -8,17 +8,17 @@
import python
from Scope s, string name, Object val
where name != "__name__" and
(
exists(ModuleObject m |
m.getModule() = s and
m.attributeRefersTo(name, val, _)
)
or
exists(ClassObject cls |
cls.getPyClass() = s and
cls.declaredAttribute(name) = val
)
)
select s.toString(), name, val.toString()
where
name != "__name__" and
(
exists(ModuleObject m |
m.getModule() = s and
m.attributeRefersTo(name, val, _)
)
or
exists(ClassObject cls |
cls.getPyClass() = s and
cls.declaredAttribute(name) = val
)
)
select s.toString(), name, val.toString()

View File

@@ -1,7 +1,8 @@
import python
from ClassObject cls, string name, BuiltinPropertyObject p
where cls.declaredAttribute(name) = p and
(cls = theObjectType() or cls = theListType() or cls = theTypeType())
select cls.toString(), name, p.toString(), p.getGetter().toString(), p.getSetter().toString(), p.getDeleter().toString()
where
cls.declaredAttribute(name) = p and
(cls = theObjectType() or cls = theListType() or cls = theTypeType())
select cls.toString(), name, p.toString(), p.getGetter().toString(), p.getSetter().toString(),
p.getDeleter().toString()

View File

@@ -1 +1 @@
| nonsense.py:1:2:1:2 | Syntax Error | Syntax Error (in Python 3.5). |
| nonsense.py:1:2:1:2 | Syntax Error | Syntax Error (in Python 3). |

View File

@@ -1,2 +1,2 @@
| async_iterator.py:26:11:26:34 | For | $@ of class '$@' may be used in for-loop. | async_iterator.py:26:20:26:33 | ControlFlowNode for MissingAiter() | Non-iterator | async_iterator.py:13:1:13:19 | class MissingAiter | MissingAiter |
| statements_test.py:34:5:34:19 | For | $@ of class '$@' may be used in for-loop. | statements_test.py:34:18:34:18 | ControlFlowNode for IntegerLiteral | Non-iterator | file://:0:0:0:0 | builtin-class int | int |
| async_iterator.py:26:11:26:34 | For | $@ of class '$@' may be used in for-loop. | async_iterator.py:26:20:26:33 | ControlFlowNode for MissingAiter() | Non-iterable | async_iterator.py:13:1:13:19 | class MissingAiter | MissingAiter |
| statements_test.py:34:5:34:19 | For | $@ of class '$@' may be used in for-loop. | statements_test.py:34:18:34:18 | ControlFlowNode for IntegerLiteral | Non-iterable | file://:0:0:0:0 | builtin-class int | int |

View File

@@ -1,17 +1,15 @@
import python
/*Find any Definition, assigned value pairs that 'valueForDefinition' misses */
Expr assignedValue(Name n) {
exists(Assign a | a.getATarget() = n and result = a.getValue())
or
exists(Alias a | a.getAsname() = n and result = a.getValue())
}
from Name def, DefinitionNode d
where d = def.getAFlowNode() and
exists(assignedValue(def)) and
not d.getValue().getNode() = assignedValue(def)
select def.toString(), assignedValue(def)
from Name def, DefinitionNode d
where
d = def.getAFlowNode() and
exists(assignedValue(def)) and
not d.getValue().getNode() = assignedValue(def)
select def.toString(), assignedValue(def)

View File

@@ -1,10 +1,10 @@
import python
int lineof(ControlFlowNode f) {
result = f.getNode().getLocation().getStartLine()
}
int lineof(ControlFlowNode f) { result = f.getNode().getLocation().getStartLine() }
from ControlFlowNode defn, ControlFlowNode use
where defn.getNode() = use.getNode()
and defn.isStore() and use.isLoad()
where
defn.getNode() = use.getNode() and
defn.isStore() and
use.isLoad()
select defn.toString(), use.toString(), lineof(defn)

View File

@@ -1,21 +1,16 @@
import python
string kind(ControlFlowNode f) {
if f.isAugLoad() then
result = "aug load"
if f.isAugLoad()
then result = "aug load"
else (
if f.isAugStore() then
result = "aug store"
if f.isAugStore()
then result = "aug store"
else (
if f.isLoad() then
result = "load"
else (
f.isStore() and result = "store"
)
if f.isLoad() then result = "load" else (f.isStore() and result = "store")
)
)
)
}
from ControlFlowNode cfg
select cfg.getLocation().getStartLine(), cfg, kind(cfg)
select cfg.getLocation().getStartLine(), cfg, kind(cfg)

View File

@@ -7,7 +7,6 @@
import python
from ControlFlowNode defn, SsaVariable v, AugAssign a, BinaryExpr b
where v.getDefinition() = defn and a.getOperation() = b and b.contains((Expr)defn.getNode())
select defn.toString(), defn.getNode().getLocation().getStartLine()
where v.getDefinition() = defn and a.getOperation() = b and b.contains(defn.getNode().(Expr))
select defn.toString(), defn.getNode().getLocation().getStartLine()

View File

@@ -8,10 +8,11 @@
import python
from CompareNode c, NameNode l, NameNode r, Cmpop op, int line, Variable vl, Variable vr
where c.operands(l, op, r) and
line = c.getLocation().getStartLine() and
line = l.getLocation().getStartLine() and
line = r.getLocation().getStartLine() and
l.uses(vl) and r.uses(vr)
where
c.operands(l, op, r) and
line = c.getLocation().getStartLine() and
line = l.getLocation().getStartLine() and
line = r.getLocation().getStartLine() and
l.uses(vl) and
r.uses(vr)
select line, c.toString(), vl.getId(), vr.getId(), op.getSymbol()

View File

@@ -2,4 +2,5 @@ import python
from ControlFlowNode p, ControlFlowNode s
where p.getASuccessor() = s
select p.getLocation().getStartLine().toString(), p.toString(), s.getLocation().getStartLine(), s.toString()
select p.getLocation().getStartLine().toString(), p.toString(), s.getLocation().getStartLine(),
s.toString()

View File

@@ -1,9 +1,8 @@
import python
select count(BasicBlock b1, BasicBlock b2
| b1 = b2.getImmediateDominator+() and not b1.strictlyDominates(b2)
),
count(BasicBlock b1, BasicBlock b2
| not b1 = b2.getImmediateDominator+() and b1.strictlyDominates(b2)
)
select count(BasicBlock b1, BasicBlock b2 |
b1 = b2.getImmediateDominator+() and not b1.strictlyDominates(b2)
),
count(BasicBlock b1, BasicBlock b2 |
not b1 = b2.getImmediateDominator+() and b1.strictlyDominates(b2)
)

View File

@@ -8,9 +8,8 @@
import python
/* This query should *never* produce a result */
from ControlFlowNode f
where not exists(f.getImmediateDominator())
and not f.getNode() instanceof Scope
where
not exists(f.getImmediateDominator()) and
not f.getNode() instanceof Scope
select f

View File

@@ -3,4 +3,3 @@ import python
from Module m, int n
where n = m.getMetrics().getNumberOfLinesOfComments()
select m.toString(), n

View File

@@ -2,5 +2,3 @@ import python
from Function func
select func.toString(), func.getMetrics().getCyclomaticComplexity()

View File

@@ -1,16 +1,19 @@
import python
predicate
can_reach_from_entry_without_passing(ControlFlowNode target, ControlFlowNode pass) {
target != pass and target.getScope() = pass.getScope() and
(target.isEntryNode() or
exists(ControlFlowNode pre | target.getAPredecessor() = pre and can_reach_from_entry_without_passing(pre, pass)))
predicate can_reach_from_entry_without_passing(ControlFlowNode target, ControlFlowNode pass) {
target != pass and
target.getScope() = pass.getScope() and
(
target.isEntryNode()
or
exists(ControlFlowNode pre |
target.getAPredecessor() = pre and can_reach_from_entry_without_passing(pre, pass)
)
)
}
from ControlFlowNode node, ControlFlowNode dom
where dom = node.getImmediateDominator()
and
can_reach_from_entry_without_passing(node, dom)
where
dom = node.getImmediateDominator() and
can_reach_from_entry_without_passing(node, dom)
select node.toString(), dom.toString()

View File

@@ -1,7 +1,8 @@
import python
from Scope s, int n
where exists(Function f | f = s | n = f.getMetrics().getNumberOfLines()) or
exists(Module m | m = s | n = m.getMetrics().getNumberOfLines())
where
exists(Function f | f = s | n = f.getMetrics().getNumberOfLines())
or
exists(Module m | m = s | n = m.getMetrics().getNumberOfLines())
select s.toString(), n

View File

@@ -1,9 +1,8 @@
import python
predicate reaches_exit(Name u) {
u.uses(_) and
exists(ControlFlowNode f, BasicBlock b |
f.getNode() = u and f.getBasicBlock() = b |
u.uses(_) and
exists(ControlFlowNode f, BasicBlock b | f.getNode() = u and f.getBasicBlock() = b |
b.reachesExit()
)
}

View File

@@ -6,12 +6,10 @@
import python
from ControlFlowNode p, ControlFlowNode s, string kind
where p.getASuccessor() = s and
(if s = p.getAnExceptionalSuccessor() then
kind = "exception"
else
kind = " normal "
) and
not p.getNode() instanceof Scope and
not s.getNode() instanceof Scope
select p.getNode().getLocation().getStartLine(), p.toString(), kind, s.getNode().getLocation().getStartLine(), s
where
p.getASuccessor() = s and
(if s = p.getAnExceptionalSuccessor() then kind = "exception" else kind = " normal ") and
not p.getNode() instanceof Scope and
not s.getNode() instanceof Scope
select p.getNode().getLocation().getStartLine(), p.toString(), kind,
s.getNode().getLocation().getStartLine(), s

View File

@@ -1,8 +1,11 @@
import python
from AstNode a, Scope s
where not a instanceof Import and not a instanceof If and not a instanceof AssignStmt and not a instanceof ExprStmt and
a.getScope() = s and
s instanceof Function
select
a.getLocation().getStartLine(), s.getName(), a, count(a.getAFlowNode())
where
not a instanceof Import and
not a instanceof If and
not a instanceof AssignStmt and
not a instanceof ExprStmt and
a.getScope() = s and
s instanceof Function
select a.getLocation().getStartLine(), s.getName(), a, count(a.getAFlowNode())

View File

@@ -1,9 +1,8 @@
import python
from ControlFlowNode p, Scope s
where
p.getScope() = s and
(exists (p.getATrueSuccessor()) or exists(p.getAFalseSuccessor())) and
s instanceof Function
select
p.getLocation().getStartLine(), s.getName(), p, strictcount(p.getASuccessor())
where
p.getScope() = s and
(exists(p.getATrueSuccessor()) or exists(p.getAFalseSuccessor())) and
s instanceof Function
select p.getLocation().getStartLine(), s.getName(), p, strictcount(p.getASuccessor())

View File

@@ -2,5 +2,5 @@ import python
from SsaVariable var, SsaVariable def
where def = var.getAnUltimateDefinition()
select var.getLocation().getFile().getShortName(),
var.toString(), var.getLocation().getStartLine(), def, def.getLocation().getStartLine()
select var.getLocation().getFile().getShortName(), var.toString(), var.getLocation().getStartLine(),
def, def.getLocation().getStartLine()

View File

@@ -1,14 +1,13 @@
import python
from SsaVariable v, string kind, ControlFlowNode use, int line
where use = v.getAUse() and
(
kind = "delete" and v.getDefinition().isDelete()
or
kind = "other " and not v.getDefinition().isDelete()
)
and line = use.getLocation().getStartLine()
and line != 0
where
use = v.getAUse() and
(
kind = "delete" and v.getDefinition().isDelete()
or
kind = "other " and not v.getDefinition().isDelete()
) and
line = use.getLocation().getStartLine() and
line != 0
select line, use.toString(), v.getId(), kind

View File

@@ -2,6 +2,5 @@ import python
from SsaVariable var, SsaVariable arg, BasicBlock pred
where pred = var.getPredecessorBlockForPhiArgument(arg)
select var.getLocation().getFile().getShortName(),
var.toString(), var.getLocation().getStartLine(), arg, arg.getLocation().getStartLine(), pred.getLastNode().getLocation().getStartLine()
select var.getLocation().getFile().getShortName(), var.toString(), var.getLocation().getStartLine(),
arg, arg.getLocation().getStartLine(), pred.getLastNode().getLocation().getStartLine()

View File

@@ -2,6 +2,5 @@ import python
from SsaVariable var, SsaVariable arg
where arg = var.getAPhiInput()
select var.getLocation().getFile().getShortName(),
var.toString(), var.getLocation().getStartLine(), arg, arg.getLocation().getStartLine()
select var.getLocation().getFile().getShortName(), var.toString(), var.getLocation().getStartLine(),
arg, arg.getLocation().getStartLine()

View File

@@ -1,7 +1,5 @@
import python
from SsaVariable var
where var.maybeUndefined()
select
var.getDefinition().getLocation().getStartLine(), var.toString()
select var.getDefinition().getLocation().getStartLine(), var.toString()

View File

@@ -2,5 +2,5 @@ import python
from ControlFlowNode use, SsaVariable def
where def.getAUse() = use
select use.getLocation().getFile().getShortName(),
use.toString(), use.getLocation().getStartLine(), def.toString(), def.getLocation().getStartLine()
select use.getLocation().getFile().getShortName(), use.toString(), use.getLocation().getStartLine(),
def.toString(), def.getLocation().getStartLine()

View File

@@ -1,7 +1,4 @@
import python
from SsaVariable var
select var.getLocation().getFile().getShortName(),
var, var.getLocation().getStartLine()
select var.getLocation().getFile().getShortName(), var, var.getLocation().getStartLine()

View File

@@ -3,16 +3,15 @@ import semmle.python.TestUtils
from ControlFlowNode p, ControlFlowNode s, string what
where
s = p.getAFalseSuccessor() and what = "false"
or
s = p.getATrueSuccessor() and what = "true"
or
s = p.getAnExceptionalSuccessor() and what = "exceptional"
or
s = p.getANormalSuccessor() and what = "normal"
or
// Add fake edges for node that raise out of scope
p.isExceptionalExit(_) and s = p.getScope().getEntryNode() and what = "exit"
select compact_location(p.getNode()), p.getNode().toString(),
compact_location(s.getNode()), s.getNode().toString(), what
s = p.getAFalseSuccessor() and what = "false"
or
s = p.getATrueSuccessor() and what = "true"
or
s = p.getAnExceptionalSuccessor() and what = "exceptional"
or
s = p.getANormalSuccessor() and what = "normal"
or
// Add fake edges for node that raise out of scope
p.isExceptionalExit(_) and s = p.getScope().getEntryNode() and what = "exit"
select compact_location(p.getNode()), p.getNode().toString(), compact_location(s.getNode()),
s.getNode().toString(), what

Some files were not shown because too many files have changed in this diff Show More