Skip to content

Commit

Permalink
Fix incorrect filename of dl()'d internal consts (php#16721)
Browse files Browse the repository at this point in the history
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 phpGH-16663
  • Loading branch information
iluuu1994 authored Nov 7, 2024
1 parent 5c76ef7 commit 452c5ac
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
11 changes: 6 additions & 5 deletions Zend/zend_constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,12 @@ 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 {
c->filename = zend_string_copy(filename);
c->filename = NULL;
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 */
Expand Down
2 changes: 2 additions & 0 deletions ext/dl_test/dl_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ PHP_MINIT_FUNCTION(dl_test)
fprintf(stderr, "DL TEST MINIT\n");
}

register_dl_test_symbols(module_number);

return SUCCESS;
}
/* }}} */
Expand Down
3 changes: 3 additions & 0 deletions ext/dl_test/dl_test.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
function dl_test_test1(): void {}

function dl_test_test2(string $str = ""): string {}

/** @var int */
const DL_TEST_CONST = 42;
7 changes: 6 additions & 1 deletion ext/dl_test/dl_test_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 452c5ac

Please sign in to comment.