Skip to content

Commit 52b13f6

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
2 parents e434385 + 882cc4f commit 52b13f6

File tree

5 files changed

+110
-10
lines changed

5 files changed

+110
-10
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ PHP NEWS
2727
. Fixed bug GH-11121 (ReflectionFiber segfault). (danog, trowski, bwoebi)
2828

2929
- FPM:
30+
. Fixed bug GH-9921 (Loading ext in FPM config does not register module
31+
handlers). (Jakub Zelenka)
3032
. Fixed bug GH-12232 (FPM: segfault dynamically loading extension without
3133
opcache). (Jakub Zelenka)
3234
. Fixed bug #76922 (FastCGI terminates conn after FCGI_GET_VALUES).

Zend/zend_API.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,7 +2383,8 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */
23832383
post_deactivate_count++;
23842384
}
23852385
} ZEND_HASH_FOREACH_END();
2386-
module_request_startup_handlers = (zend_module_entry**)malloc(
2386+
module_request_startup_handlers = (zend_module_entry**)realloc(
2387+
module_request_startup_handlers,
23872388
sizeof(zend_module_entry*) *
23882389
(startup_count + 1 +
23892390
shutdown_count + 1 +
@@ -2415,7 +2416,8 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */
24152416
}
24162417
} ZEND_HASH_FOREACH_END();
24172418

2418-
class_cleanup_handlers = (zend_class_entry**)malloc(
2419+
class_cleanup_handlers = (zend_class_entry**)realloc(
2420+
class_cleanup_handlers,
24192421
sizeof(zend_class_entry*) *
24202422
(class_count + 1));
24212423
class_cleanup_handlers[class_count] = NULL;
@@ -2441,7 +2443,9 @@ ZEND_API void zend_startup_modules(void) /* {{{ */
24412443
ZEND_API void zend_destroy_modules(void) /* {{{ */
24422444
{
24432445
free(class_cleanup_handlers);
2446+
class_cleanup_handlers = NULL;
24442447
free(module_request_startup_handlers);
2448+
module_request_startup_handlers = NULL;
24452449
zend_hash_graceful_reverse_destroy(&module_registry);
24462450
}
24472451
/* }}} */

ext/dl_test/dl_test.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ PHP_MINIT_FUNCTION(dl_test)
9090
zend_register_functions(NULL, php_dl_test_use_register_functions_directly_functions, NULL, type);
9191
}
9292

93+
if (getenv("PHP_DL_TEST_MODULE_DEBUG")) {
94+
fprintf(stderr, "DL TEST MINIT\n");
95+
}
96+
9397
return SUCCESS;
9498
}
9599
/* }}} */
@@ -104,6 +108,10 @@ static PHP_MSHUTDOWN_FUNCTION(dl_test)
104108
UNREGISTER_INI_ENTRIES();
105109
}
106110

111+
if (getenv("PHP_DL_TEST_MODULE_DEBUG")) {
112+
fprintf(stderr, "DL TEST MSHUTDOWN\n");
113+
}
114+
107115
return SUCCESS;
108116
}
109117
/* }}} */
@@ -115,6 +123,21 @@ PHP_RINIT_FUNCTION(dl_test)
115123
ZEND_TSRMLS_CACHE_UPDATE();
116124
#endif
117125

126+
if (getenv("PHP_DL_TEST_MODULE_DEBUG")) {
127+
fprintf(stderr, "DL TEST RINIT\n");
128+
}
129+
130+
return SUCCESS;
131+
}
132+
/* }}} */
133+
134+
/* {{{ PHP_RSHUTDOWN_FUNCTION */
135+
PHP_RSHUTDOWN_FUNCTION(dl_test)
136+
{
137+
if (getenv("PHP_DL_TEST_MODULE_DEBUG")) {
138+
fprintf(stderr, "DL TEST RSHUTDOWN\n");
139+
}
140+
118141
return SUCCESS;
119142
}
120143
/* }}} */
@@ -148,7 +171,7 @@ zend_module_entry dl_test_module_entry = {
148171
PHP_MINIT(dl_test),
149172
PHP_MSHUTDOWN(dl_test),
150173
PHP_RINIT(dl_test),
151-
NULL,
174+
PHP_RSHUTDOWN(dl_test),
152175
PHP_MINFO(dl_test),
153176
PHP_DL_TEST_VERSION,
154177
PHP_MODULE_GLOBALS(dl_test),

sapi/fpm/fpm/fpm_php.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ static void fpm_php_disable(char *value, int (*zend_disable)(const char *, size_
7777
}
7878
/* }}} */
7979

80+
#define FPM_PHP_INI_ALTERING_ERROR -1
81+
#define FPM_PHP_INI_APPLIED 1
82+
#define FPM_PHP_INI_EXTENSION_FAILED 0
83+
#define FPM_PHP_INI_EXTENSION_LOADED 2
84+
8085
int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode) /* {{{ */
8186
{
8287

@@ -90,45 +95,57 @@ int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode) /* {{{ */
9095
zend_interned_strings_switch_storage(0);
9196
php_dl(value, MODULE_PERSISTENT, &zv, 1);
9297
zend_interned_strings_switch_storage(1);
93-
return Z_TYPE(zv) == IS_TRUE;
98+
return Z_TYPE(zv) == IS_TRUE ? FPM_PHP_INI_EXTENSION_LOADED : FPM_PHP_INI_EXTENSION_FAILED;
9499
}
95100

96101
if (fpm_php_zend_ini_alter_master(name, name_len, value, value_len, mode, PHP_INI_STAGE_ACTIVATE) == FAILURE) {
97-
return -1;
102+
return FPM_PHP_INI_ALTERING_ERROR;
98103
}
99104

100105
if (!strcmp(name, "disable_functions") && *value) {
101106
zend_disable_functions(value);
102-
return 1;
107+
return FPM_PHP_INI_APPLIED;
103108
}
104109

105110
if (!strcmp(name, "disable_classes") && *value) {
106111
char *v = strdup(value);
107112
PG(disable_classes) = v;
108113
fpm_php_disable(v, zend_disable_class);
109-
return 1;
114+
return FPM_PHP_INI_APPLIED;
110115
}
111116

112-
return 1;
117+
return FPM_PHP_INI_APPLIED;
113118
}
114119
/* }}} */
115120

116121
static int fpm_php_apply_defines(struct fpm_worker_pool_s *wp) /* {{{ */
117122
{
118123
struct key_value_s *kv;
124+
int apply_result;
125+
bool extension_loaded = false;
119126

120127
for (kv = wp->config->php_values; kv; kv = kv->next) {
121-
if (fpm_php_apply_defines_ex(kv, ZEND_INI_USER) == -1) {
128+
apply_result = fpm_php_apply_defines_ex(kv, ZEND_INI_USER);
129+
if (apply_result == FPM_PHP_INI_ALTERING_ERROR) {
122130
zlog(ZLOG_ERROR, "Unable to set php_value '%s'", kv->key);
131+
} else if (apply_result == FPM_PHP_INI_EXTENSION_LOADED) {
132+
extension_loaded = true;
123133
}
124134
}
125135

126136
for (kv = wp->config->php_admin_values; kv; kv = kv->next) {
127-
if (fpm_php_apply_defines_ex(kv, ZEND_INI_SYSTEM) == -1) {
137+
apply_result = fpm_php_apply_defines_ex(kv, ZEND_INI_SYSTEM);
138+
if (apply_result == FPM_PHP_INI_ALTERING_ERROR) {
128139
zlog(ZLOG_ERROR, "Unable to set php_admin_value '%s'", kv->key);
140+
} else if (apply_result == FPM_PHP_INI_EXTENSION_LOADED) {
141+
extension_loaded = true;
129142
}
130143
}
131144

145+
if (extension_loaded) {
146+
zend_collect_module_handlers();
147+
}
148+
132149
return 0;
133150
}
134151
/* }}} */
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
--TEST--
2+
FPM: GH-9921 - loading shared ext in FPM config does not register module handlers
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+
env[PHP_DL_TEST_MODULE_DEBUG] = 1
23+
php_admin_value[extension] = dl_test
24+
EOT;
25+
26+
$code = <<<EOT
27+
<?php
28+
var_dump(extension_loaded('dl_test'));
29+
EOT;
30+
31+
$tester = new FPM\Tester($cfg, $code);
32+
$tester->start();
33+
$tester->expectLogStartNotices();
34+
$tester->request()->expectBody('bool(true)');
35+
$tester->expectLogPattern('/DL TEST MINIT/');
36+
$tester->expectLogPattern('/DL TEST RINIT/');
37+
$tester->expectLogPattern('/DL TEST RSHUTDOWN/');
38+
$tester->request()->expectBody('bool(true)');
39+
$tester->expectLogPattern('/DL TEST RINIT/');
40+
$tester->expectLogPattern('/DL TEST RSHUTDOWN/');
41+
$tester->terminate();
42+
$tester->expectLogTerminatingNotices();
43+
$tester->close();
44+
45+
?>
46+
Done
47+
--EXPECT--
48+
Done
49+
--CLEAN--
50+
<?php
51+
require_once "tester.inc";
52+
FPM\Tester::clean();
53+
?>
54+
<?php

0 commit comments

Comments
 (0)