Skip to content

Commit 9b6afd8

Browse files
authored
Make sure core module has number 0 (#12272)
* Make sure core module has number 0 Some places, possibly also outside PHP, assume the core extension has module number 0. After 8a812c3 this wasn't the case anymore as reported in [1]. Fix it by changing how the next module ID is computed. [1] #12246 (comment) * Add assertion * Add test
1 parent f1f04cf commit 9b6afd8

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

Zend/zend_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3271,7 +3271,7 @@ ZEND_API void zend_post_deactivate_modules(void) /* {{{ */
32713271
/* return the next free module number */
32723272
ZEND_API int zend_next_free_module(void) /* {{{ */
32733273
{
3274-
return zend_hash_num_elements(&module_registry) + 1;
3274+
return zend_hash_num_elements(&module_registry);
32753275
}
32763276
/* }}} */
32773277

Zend/zend_builtin_functions.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ zend_module_entry zend_builtin_module = { /* {{{ */
5959

6060
zend_result zend_startup_builtin_functions(void) /* {{{ */
6161
{
62-
return (EG(current_module) = zend_register_module_ex(&zend_builtin_module, MODULE_PERSISTENT)) == NULL ? FAILURE : SUCCESS;
62+
zend_module_entry *module;
63+
EG(current_module) = module = zend_register_module_ex(&zend_builtin_module, MODULE_PERSISTENT);
64+
if (UNEXPECTED(module == NULL)) {
65+
return FAILURE;
66+
}
67+
ZEND_ASSERT(module->module_number == 0);
68+
return SUCCESS;
6369
}
6470
/* }}} */
6571

sapi/cli/tests/025.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
CLI php -i extension_dir
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
if (substr(PHP_OS, 0, 3) == 'WIN') {
7+
die ("skip not for Windows");
8+
}
9+
?>
10+
--FILE--
11+
<?php
12+
13+
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
14+
$output = `$php -n -i`;
15+
var_dump(str_contains($output, "extension_dir => "));
16+
17+
?>
18+
--EXPECT--
19+
bool(true)

0 commit comments

Comments
 (0)