From 240a3b3ff226dddfbfa9e587bf602487599ea047 Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Fri, 22 Sep 2023 22:02:19 +0100 Subject: [PATCH] Fix GH-12232: FPM: segfault dynamically loading extension without opcache Also fixes incorrect assertion in ini init that php_dl is always temporary. Closes GH-12277 --- Zend/zend_ini.c | 1 - sapi/fpm/fpm/fpm_php.c | 2 + .../tests/gh12232-php-value-extension.phpt | 51 +++++++++++++++++++ sapi/fpm/tests/tester.inc | 11 ++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 sapi/fpm/tests/gh12232-php-value-extension.phpt diff --git a/Zend/zend_ini.c b/Zend/zend_ini.c index 1b4710eb503a..866e1b9c2097 100644 --- a/Zend/zend_ini.c +++ b/Zend/zend_ini.c @@ -211,7 +211,6 @@ ZEND_API zend_result zend_register_ini_entries_ex(const zend_ini_entry_def *ini_ * lead to death. */ if (directives != EG(ini_directives)) { - ZEND_ASSERT(module_type == MODULE_TEMPORARY); directives = EG(ini_directives); } else { ZEND_ASSERT(module_type == MODULE_PERSISTENT); diff --git a/sapi/fpm/fpm/fpm_php.c b/sapi/fpm/fpm/fpm_php.c index 92b189668206..a9ad0433ba4d 100644 --- a/sapi/fpm/fpm/fpm_php.c +++ b/sapi/fpm/fpm/fpm_php.c @@ -87,7 +87,9 @@ int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode) /* {{{ */ if (!strcmp(name, "extension") && *value) { zval zv; + zend_interned_strings_switch_storage(0); php_dl(value, MODULE_PERSISTENT, &zv, 1); + zend_interned_strings_switch_storage(1); return Z_TYPE(zv) == IS_TRUE; } diff --git a/sapi/fpm/tests/gh12232-php-value-extension.phpt b/sapi/fpm/tests/gh12232-php-value-extension.phpt new file mode 100644 index 000000000000..207bd7a67797 --- /dev/null +++ b/sapi/fpm/tests/gh12232-php-value-extension.phpt @@ -0,0 +1,51 @@ +--TEST-- +FPM: gh12232 - loading shared ext in FPM config +--SKIPIF-- + +--FILE-- +start(); +$tester->expectLogStartNotices(); +$tester->request()->expectBody(['bool(true)', 'string(5) "hello"', 'string(4) "test"']); +$tester->request()->expectBody(['bool(true)', 'string(5) "hello"', 'string(4) "test"']); +$tester->terminate(); +$tester->expectLogTerminatingNotices(); +$tester->close(); + +?> +Done +--EXPECT-- +Done +--CLEAN-- + +