com php-src: Fixed bug #75786: NEWS Zend/tests/bug75786.phpt Zend/zend_vm_def.h Zend/zend_vm_execute.h

From: Date: Tue, 09 Jan 2018 19:20:31 +0000
Subject: com php-src: Fixed bug #75786: NEWS Zend/tests/bug75786.phpt Zend/zend_vm_def.h Zend/zend_vm_execute.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-100819@lists.php.net to get a copy of this message
Commit: fd30c59e041eb4ccaabb2099bb3be15a55e2988d Author: Nikita Popov <nikita.ppv@gmail.com> Tue, 9 Jan 2018 20:20:31 +0100 Parents: f208187773edd9423e64b5b4dd16b146260c780d Branches: PHP-7.1 PHP-7.2 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=fd30c59e041eb4ccaabb2099bb3be15a55e2988d Log: Fixed bug #75786 SEND_UNPACK on iterators was duplicating references in-place, which effectively leaks the original value and causes an off-by-one refcount on the duplicated value. Replace this with a deref, as an actual duplication is not even needed in this case. Bugs: https://bugs.php.net/75786 Changed paths: M NEWS A Zend/tests/bug75786.phpt M Zend/zend_vm_def.h M Zend/zend_vm_execute.h Diff: diff --git a/NEWS b/NEWS index 67dfb46..8414fcd 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ PHP NEWS - Core: . Fixed bug #75679 (Path 260 character problem). (Anatol) + . Fixed bug #75786 (segfault when using spread operator on generator passed + by reference). (Nikita) - Opcache: . Fixed bug #75720 (File cache not populated after SHM runs full). (Dmitry) diff --git a/Zend/tests/bug75786.phpt b/Zend/tests/bug75786.phpt new file mode 100644 index 0000000..b93111b --- /dev/null +++ b/Zend/tests/bug75786.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #75786: segfault when using spread operator on generator passed by reference +--FILE-- +<?php + +function &gen($items) { + foreach ($items as $key => &$value) { + yield $key => $value; + } +} + +var_dump(...gen(['a', 'b', 'c'])); + +?> +--EXPECT-- +string(1) "a" +string(1) "b" +string(1) "c" diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 8f68cda..7dd70fa 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -4647,11 +4647,8 @@ ZEND_VM_C_LABEL(send_again): ); } - if (Z_ISREF_P(arg)) { - ZVAL_DUP(arg, Z_REFVAL_P(arg)); - } else { - if (Z_REFCOUNTED_P(arg)) Z_ADDREF_P(arg); - } + ZVAL_DEREF(arg); + Z_TRY_ADDREF_P(arg); zend_vm_stack_extend_call_frame(&EX(call), arg_num - 1, 1); top = ZEND_CALL_ARG(EX(call), arg_num); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index a9735b1..cb20546 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -1358,11 +1358,8 @@ send_again: ); } - if (Z_ISREF_P(arg)) { - ZVAL_DUP(arg, Z_REFVAL_P(arg)); - } else { - if (Z_REFCOUNTED_P(arg)) Z_ADDREF_P(arg); - } + ZVAL_DEREF(arg); + Z_TRY_ADDREF_P(arg); zend_vm_stack_extend_call_frame(&EX(call), arg_num - 1, 1); top = ZEND_CALL_ARG(EX(call), arg_num);

« previous php.cvs (#100819) next »