Skip to content

Fix GH-12232: FPM: segfault dynamically loading extension without opcache #12277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Zend/zend_ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions sapi/fpm/fpm/fpm_php.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
51 changes: 51 additions & 0 deletions sapi/fpm/tests/gh12232-php-value-extension.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--TEST--
FPM: gh12232 - loading shared ext in FPM config
--SKIPIF--
<?php
include "skipif.inc";
FPM\Tester::skipIfSharedExtensionNotFound('dl_test');
?>
--FILE--
<?php

require_once "tester.inc";

$cfg = <<<EOT
[global]
error_log = {{FILE:LOG}}
[unconfined]
listen = {{ADDR}}
pm = static
pm.max_children = 1
pm.status_path = /status
catch_workers_output = yes
php_admin_value[extension] = dl_test
EOT;

$code = <<<EOT
<?php
var_dump(extension_loaded('dl_test'));
var_dump(ini_get('dl_test.string'));
ini_set('dl_test.string', 'test');
var_dump(ini_get('dl_test.string'));
EOT;

$tester = new FPM\Tester($cfg, $code);
$tester->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--
<?php
require_once "tester.inc";
FPM\Tester::clean();
?>
<?php
11 changes: 11 additions & 0 deletions sapi/fpm/tests/tester.inc
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,17 @@ class Tester
}
}

/**
* Skip if shared extension is not available in extension directory.
*/
static public function skipIfSharedExtensionNotFound($extensionName)
{
$soPath = ini_get('extension_dir') . '/' . $extensionName . '.so';
if ( ! file_exists($soPath)) {
die("skip $extensionName extension not present in extension_dir");
}
}

/**
* Tester constructor.
*
Expand Down