mirror of
https://github.com/github/codeql.git
synced 2025-12-23 12:16:33 +01:00
Python: Make py/side-effect-in-assert handle example
Also removed parantheses
This commit is contained in:
@@ -1 +1 @@
|
||||
assert(subprocess.call(['run-backup']) == 0)
|
||||
assert subprocess.call(['run-backup']) == 0
|
||||
|
||||
@@ -28,6 +28,14 @@ predicate func_with_side_effects(Expr e) {
|
||||
)
|
||||
}
|
||||
|
||||
predicate call_with_side_effect(Call e) {
|
||||
e.getAFlowNode() = Value::named("subprocess.call").getACall()
|
||||
or
|
||||
e.getAFlowNode() = Value::named("subprocess.check_call").getACall()
|
||||
or
|
||||
e.getAFlowNode() = Value::named("subprocess.check_output").getACall()
|
||||
}
|
||||
|
||||
predicate probable_side_effect(Expr e) {
|
||||
// Only consider explicit yields, not artificial ones in comprehensions
|
||||
e instanceof Yield and not exists(Comp c | c.contains(e))
|
||||
@@ -35,6 +43,8 @@ predicate probable_side_effect(Expr e) {
|
||||
e instanceof YieldFrom
|
||||
or
|
||||
e instanceof Call and func_with_side_effects(e.(Call).getFunc())
|
||||
or
|
||||
e instanceof Call and call_with_side_effect(e)
|
||||
}
|
||||
|
||||
from Assert a, Expr e
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
| assert.py:5:5:5:20 | Assert | This 'assert' statement contains $@ which may have side effects. | assert.py:5:13:5:19 | Yield | an expression |
|
||||
| assert.py:8:5:8:22 | Assert | This 'assert' statement contains $@ which may have side effects. | assert.py:8:12:8:22 | Attribute() | an expression |
|
||||
| assert.py:20:1:20:43 | Assert | This 'assert' statement contains $@ which may have side effects. | assert.py:20:8:20:38 | Attribute() | an expression |
|
||||
|
||||
@@ -16,8 +16,8 @@ def assert_tuple(x, y):
|
||||
assert ()
|
||||
assert (x, y)
|
||||
|
||||
|
||||
|
||||
import subprocess
|
||||
assert subprocess.call(['run-backup']) == 0 # TODO: FN
|
||||
|
||||
|
||||
|
||||
@@ -103,4 +103,4 @@ def error_assert_in_intermediate_branch(x):
|
||||
elif yks(x):
|
||||
pass
|
||||
else:
|
||||
pass
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user