Skip to content

Commit f288d9c

Browse files
committed
Merge branch 'PHP-8.3'
2 parents a66c926 + 52b13f6 commit f288d9c

File tree

4 files changed

+108
-10
lines changed

4 files changed

+108
-10
lines changed

Zend/zend_API.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,7 +2389,8 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */
23892389
post_deactivate_count++;
23902390
}
23912391
} ZEND_HASH_FOREACH_END();
2392-
module_request_startup_handlers = (zend_module_entry**)malloc(
2392+
module_request_startup_handlers = (zend_module_entry**)realloc(
2393+
module_request_startup_handlers,
23932394
sizeof(zend_module_entry*) *
23942395
(startup_count + 1 +
23952396
shutdown_count + 1 +
@@ -2421,7 +2422,8 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */
24212422
}
24222423
} ZEND_HASH_FOREACH_END();
24232424

2424-
class_cleanup_handlers = (zend_class_entry**)malloc(
2425+
class_cleanup_handlers = (zend_class_entry**)realloc(
2426+
class_cleanup_handlers,
24252427
sizeof(zend_class_entry*) *
24262428
(class_count + 1));
24272429
class_cleanup_handlers[class_count] = NULL;
@@ -2447,7 +2449,9 @@ ZEND_API void zend_startup_modules(void) /* {{{ */
24472449
ZEND_API void zend_destroy_modules(void) /* {{{ */
24482450
{
24492451
free(class_cleanup_handlers);
2452+
class_cleanup_handlers = NULL;
24502453
free(module_request_startup_handlers);
2454+
module_request_startup_handlers = NULL;
24512455
zend_hash_graceful_reverse_destroy(&module_registry);
24522456
}
24532457
/* }}} */

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)