Fix incorrect filename of dl()'d internal consts (#16721)

We should only attempt to fetch the current filename for user constants. dl()
may attempt to register internal constants after execution has already started,
thus incorrectly linking the user file invoking dl().

See GH-16663
This commit is contained in:
Ilija Tovilo 2024-11-07 14:53:12 +01:00 committed by GitHub
parent 5c76ef78cb
commit 452c5ac989
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17 additions and 6 deletions

View file

@ -504,12 +504,13 @@ ZEND_API zend_result zend_register_constant(zend_constant *c)
name = c->name;
}
zend_string *filename = zend_get_executed_filename_ex();
if (filename == NULL) {
c->filename = NULL;
} else {
if (ZEND_CONSTANT_MODULE_NUMBER(c) == PHP_USER_CONSTANT) {
zend_string *filename = zend_get_executed_filename_ex();
if (filename) {
c->filename = zend_string_copy(filename);
}
}
/* Check if the user is trying to define any special constant */
if (zend_string_equals_literal(name, "__COMPILER_HALT_OFFSET__")

View file

@ -94,6 +94,8 @@ PHP_MINIT_FUNCTION(dl_test)
fprintf(stderr, "DL TEST MINIT\n");
}
register_dl_test_symbols(module_number);
return SUCCESS;
}
/* }}} */

View file

@ -8,3 +8,6 @@
function dl_test_test1(): void {}
function dl_test_test2(string $str = ""): string {}
/** @var int */
const DL_TEST_CONST = 42;

View file

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 547ddbc21e9aa853b491cb17e902bbbb9cc2df00 */
* Stub hash: e1154d736a190512ecf51e30719d53e685ca5513 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_dl_test_test1, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()
@ -16,3 +16,8 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(dl_test_test2, arginfo_dl_test_test2)
ZEND_FE_END
};
static void register_dl_test_symbols(int module_number)
{
REGISTER_LONG_CONSTANT("DL_TEST_CONST", 42, CONST_PERSISTENT);
}