]> granicus.if.org Git - python/commitdiff
Add NULL check for gen->gi_code in gen_send_ex()
authorChristian Heimes <christian@python.org>
Thu, 8 Sep 2016 22:20:13 +0000 (00:20 +0200)
committerChristian Heimes <christian@python.org>
Thu, 8 Sep 2016 22:20:13 +0000 (00:20 +0200)
_PyGen_Finalize() checks that gen->gi_code is not NULL before it
accesses the flags of the code object. This means that the flag
could be NULL.

It passes down the generatore to gen_close() and gen_send_ex().
gen_send_ex() did not check for gen->gi_code != NULL.

CID 1297900

Objects/genobject.c

index 562d41d674c5cc2c2aa145921d6419c230460c40..19d388eeebfe491283f9175f372b4a9009914194 100644 (file)
@@ -167,7 +167,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing)
         /* Check for __future__ generator_stop and conditionally turn
          * a leaking StopIteration into RuntimeError (with its cause
          * set appropriately). */
-        if (((PyCodeObject *)gen->gi_code)->co_flags &
+        if (gen->gi_code != NULL && ((PyCodeObject *)gen->gi_code)->co_flags &
               (CO_FUTURE_GENERATOR_STOP | CO_COROUTINE | CO_ITERABLE_COROUTINE))
         {
             PyObject *exc, *val, *val2, *tb;