com php-src: Fix memory error when throwing into a generator: Zend/zend_generators.c

From: Date: Fri, 17 Apr 2015 20:19:41 +0000
Subject: com php-src: Fix memory error when throwing into a generator: Zend/zend_generators.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-86362@lists.php.net to get a copy of this message
Commit: 9a0cb734a390e38be87baabf45a895ccf7d64712 Author: Nikita Popov <nikic@php.net> Fri, 17 Apr 2015 22:19:41 +0200 Parents: ffa285ca7329d658737483d5beae5cce56d107dc Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9a0cb734a390e38be87baabf45a895ccf7d64712 Log: Fix memory error when throwing into a generator throw_exception_internal will access opline+1, which is not always defined at the current opline of the generator. To avoid this decrement the opline before throwing (so the throw occurs at the YIELD opcode instead of one after it). Changed paths: M Zend/zend_generators.c Diff: diff --git a/Zend/zend_generators.c b/Zend/zend_generators..c index 7d2472a..ea84950 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -313,14 +313,17 @@ ZEND_API zend_execute_data *zend_generator_check_placeholder_frame(zend_execute_ static void zend_generator_throw_exception(zend_generator *generator, zval *exception) { - /* Throw the exception in the context of the generator */ + /* Throw the exception in the context of the generator. Decrementing the opline + * to pretend the exception happened during the YIELD opcode. */ zend_execute_data *original_execute_data = EG(current_execute_data); EG(current_execute_data) = generator->execute_data; + generator->execute_data->opline--; if (exception) { zend_throw_exception_object(exception); } else { zend_throw_exception_internal(NULL); } + generator->execute_data->opline++; EG(current_execute_data) = original_execute_data; }

« previous php.cvs (#86362) next »