Skip to content

Commit 240a3b3

Browse files
committed
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
1 parent 36a87e6 commit 240a3b3

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

Zend/zend_ini.c

-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ ZEND_API zend_result zend_register_ini_entries_ex(const zend_ini_entry_def *ini_
211211
* lead to death.
212212
*/
213213
if (directives != EG(ini_directives)) {
214-
ZEND_ASSERT(module_type == MODULE_TEMPORARY);
215214
directives = EG(ini_directives);
216215
} else {
217216
ZEND_ASSERT(module_type == MODULE_PERSISTENT);

sapi/fpm/fpm/fpm_php.c

+2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode) /* {{{ */
8787

8888
if (!strcmp(name, "extension") && *value) {
8989
zval zv;
90+
zend_interned_strings_switch_storage(0);
9091
php_dl(value, MODULE_PERSISTENT, &zv, 1);
92+
zend_interned_strings_switch_storage(1);
9193
return Z_TYPE(zv) == IS_TRUE;
9294
}
9395

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--TEST--
2+
FPM: gh12232 - loading shared ext in FPM config
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
FPM\Tester::skipIfSharedExtensionNotFound('dl_test');
7+
?>
8+
--FILE--
9+
<?php
10+
11+
require_once "tester.inc";
12+
13+
$cfg = <<<EOT
14+
[global]
15+
error_log = {{FILE:LOG}}
16+
[unconfined]
17+
listen = {{ADDR}}
18+
pm = static
19+
pm.max_children = 1
20+
pm.status_path = /status
21+
catch_workers_output = yes
22+
php_admin_value[extension] = dl_test
23+
EOT;
24+
25+
$code = <<<EOT
26+
<?php
27+
var_dump(extension_loaded('dl_test'));
28+
var_dump(ini_get('dl_test.string'));
29+
ini_set('dl_test.string', 'test');
30+
var_dump(ini_get('dl_test.string'));
31+
EOT;
32+
33+
$tester = new FPM\Tester($cfg, $code);
34+
$tester->start();
35+
$tester->expectLogStartNotices();
36+
$tester->request()->expectBody(['bool(true)', 'string(5) "hello"', 'string(4) "test"']);
37+
$tester->request()->expectBody(['bool(true)', 'string(5) "hello"', 'string(4) "test"']);
38+
$tester->terminate();
39+
$tester->expectLogTerminatingNotices();
40+
$tester->close();
41+
42+
?>
43+
Done
44+
--EXPECT--
45+
Done
46+
--CLEAN--
47+
<?php
48+
require_once "tester.inc";
49+
FPM\Tester::clean();
50+
?>
51+
<?php

sapi/fpm/tests/tester.inc

+11
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,17 @@ class Tester
319319
}
320320
}
321321

322+
/**
323+
* Skip if shared extension is not available in extension directory.
324+
*/
325+
static public function skipIfSharedExtensionNotFound($extensionName)
326+
{
327+
$soPath = ini_get('extension_dir') . '/' . $extensionName . '.so';
328+
if ( ! file_exists($soPath)) {
329+
die("skip $extensionName extension not present in extension_dir");
330+
}
331+
}
332+
322333
/**
323334
* Tester constructor.
324335
*

0 commit comments

Comments
 (0)