mirror of
https://github.com/github/codeql.git
synced 2025-12-19 18:33:16 +01:00
Merge pull request #2991 from BekaValentine/python-objectapi-to-valueapi-unguardednextingenerator
Python: ObjectAPI to ValueAPI: UnguardedNextInGenerator
This commit is contained in:
@@ -12,12 +12,12 @@
|
||||
|
||||
import python
|
||||
|
||||
FunctionObject iter() {
|
||||
result = Object::builtin("iter")
|
||||
FunctionValue iter() {
|
||||
result = Value::named("iter")
|
||||
}
|
||||
|
||||
BuiltinFunctionObject next() {
|
||||
result = Object::builtin("next")
|
||||
BuiltinFunctionValue next() {
|
||||
result = Value::named("next")
|
||||
}
|
||||
|
||||
predicate call_to_iter(CallNode call, EssaVariable sequence) {
|
||||
@@ -28,6 +28,10 @@ predicate call_to_next(CallNode call, ControlFlowNode iter) {
|
||||
iter = next().getArgumentForCall(call, 0)
|
||||
}
|
||||
|
||||
predicate call_to_next_has_default(CallNode call) {
|
||||
exists(call.getArg(1)) or exists(call.getArgByName("default"))
|
||||
}
|
||||
|
||||
predicate guarded_not_empty_sequence(EssaVariable sequence) {
|
||||
sequence.getDefinition() instanceof EssaEdgeRefinement
|
||||
}
|
||||
@@ -43,12 +47,13 @@ predicate iter_not_exhausted(EssaVariable iterator) {
|
||||
predicate stop_iteration_handled(CallNode call) {
|
||||
exists(Try t |
|
||||
t.containsInScope(call.getNode()) and
|
||||
t.getAHandler().getType().refersTo(theStopIterationType())
|
||||
t.getAHandler().getType().pointsTo(ClassValue::stopIteration())
|
||||
)
|
||||
}
|
||||
|
||||
from CallNode call
|
||||
where call_to_next(call, _) and
|
||||
not call_to_next_has_default(call) and
|
||||
not exists(EssaVariable iterator |
|
||||
call_to_next(call, iterator.getAUse()) and
|
||||
iter_not_exhausted(iterator)
|
||||
@@ -58,4 +63,3 @@ not exists(Comp comp | comp.contains(call.getNode())) and
|
||||
not stop_iteration_handled(call)
|
||||
|
||||
select call, "Call to next() in a generator"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user