diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-05-04 16:27:45 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-05-04 16:27:45 +0200 |
commit | 21a9ad910bc1a890ca4bddc4d4239c2e17d4c6a6 (patch) | |
tree | 0de7f5caf07ebdf5f71c7773587c3ff59f06e8db | |
parent | 733d84dbdf8f278fc0060a4fb5b2766c035c3b1f (diff) | |
download | php-git-21a9ad910bc1a890ca4bddc4d4239c2e17d4c6a6.tar.gz |
Fixed bug #79548
When duplicating user functions with static variables, make sure
that we init a new map ptr slot for the static variables.
-rw-r--r-- | Zend/zend_inheritance.c | 9 | ||||
-rw-r--r-- | ext/opcache/tests/preload_static_var_inheritance.inc | 9 | ||||
-rw-r--r-- | ext/opcache/tests/preload_static_var_inheritance.phpt | 18 |
3 files changed, 35 insertions, 1 deletions
diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index 6bd35a6bb7..e7dcf54e0d 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -86,7 +86,14 @@ static zend_function *zend_duplicate_user_function(zend_function *func) /* {{{ * if (!(GC_FLAGS(new_function->op_array.static_variables) & IS_ARRAY_IMMUTABLE)) { GC_ADDREF(new_function->op_array.static_variables); } - ZEND_MAP_PTR_INIT(new_function->op_array.static_variables_ptr, &new_function->op_array.static_variables); + + if (CG(compiler_options) & ZEND_COMPILE_PRELOAD) { + ZEND_ASSERT(new_function->op_array.fn_flags & ZEND_ACC_PRELOADED); + ZEND_MAP_PTR_NEW(new_function->op_array.static_variables_ptr); + } else { + ZEND_MAP_PTR_INIT(new_function->op_array.static_variables_ptr, &new_function->op_array.static_variables); + } + return new_function; } /* }}} */ diff --git a/ext/opcache/tests/preload_static_var_inheritance.inc b/ext/opcache/tests/preload_static_var_inheritance.inc new file mode 100644 index 0000000000..56ed65c2c0 --- /dev/null +++ b/ext/opcache/tests/preload_static_var_inheritance.inc @@ -0,0 +1,9 @@ +<?php + +class A { + public function test() { + static $foo; + } +} + +class B extends A {} diff --git a/ext/opcache/tests/preload_static_var_inheritance.phpt b/ext/opcache/tests/preload_static_var_inheritance.phpt new file mode 100644 index 0000000000..dd5e4308a9 --- /dev/null +++ b/ext/opcache/tests/preload_static_var_inheritance.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #79548: Preloading segfault with inherited method using static variable +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +opcache.preload={PWD}/preload_static_var_inheritance.inc +--SKIPIF-- +<?php +require_once('skipif.inc'); +if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows'); +?> +--FILE-- +<?php +var_dump((new B)->test()); +?> +--EXPECT-- +NULL |