diff options
| author | Nikita Popov <nikic@php.net> | 2015-04-17 22:19:41 +0200 |
|---|---|---|
| committer | Nikita Popov <nikic@php.net> | 2015-04-17 22:19:41 +0200 |
| commit | 9a0cb734a390e38be87baabf45a895ccf7d64712 (patch) | |
| tree | 26f2460ddd5ec71f48ca9bfeed9a502a2e09c9eb /Zend/zend_generators.c | |
| parent | ffa285ca7329d658737483d5beae5cce56d107dc (diff) | |
| download | php-git-9a0cb734a390e38be87baabf45a895ccf7d64712.tar.gz | |
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).
Diffstat (limited to 'Zend/zend_generators.c')
| -rw-r--r-- | Zend/zend_generators.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index 7d2472a145..ea84950691 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; } |
