mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Don't bail when closing resources on shutdown
This commit is contained in:
1
NEWS
1
NEWS
@@ -5,6 +5,7 @@ PHP NEWS
|
||||
- Core:
|
||||
. Fixed bug GH-20113 (Missing new Foo(...) error in constant expressions).
|
||||
(ilutov)
|
||||
. Fixed bug GH-19844 (Don't bail when closing resources on shutdown). (ilutov)
|
||||
|
||||
- FPM:
|
||||
. Fixed bug GH-19817 (Decode SCRIPT_FILENAME issue in php 8.5).
|
||||
|
||||
46
Zend/tests/gh19844.phpt
Normal file
46
Zend/tests/gh19844.phpt
Normal file
@@ -0,0 +1,46 @@
|
||||
--TEST--
|
||||
GH-19844: Bail from stream_close() in zend_shutdown_executor_values()
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (substr(PHP_OS, 0, 3) == 'WIN') die('skip Aborts with STATUS_BAD_FUNCTION_TABLE on Windows');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class Test {
|
||||
public $context;
|
||||
private static $nested = false;
|
||||
|
||||
function stream_open() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function stream_read() {
|
||||
return '.';
|
||||
}
|
||||
function stream_set_option() {}
|
||||
function stream_stat() {}
|
||||
|
||||
function stream_eof() {
|
||||
if (!Test::$nested) {
|
||||
Test::$nested = true;
|
||||
include 'Test://';
|
||||
}
|
||||
@trigger_error('Bail', E_USER_ERROR);
|
||||
}
|
||||
|
||||
function stream_close() {
|
||||
@trigger_error('Bail', E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
stream_wrapper_register('Test', Test::class);
|
||||
include 'Test://';
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Bail in %s on line %d
|
||||
|
||||
Fatal error: Bail in %s on line %d
|
||||
|
||||
Fatal error: Bail in %s on line %d
|
||||
@@ -274,9 +274,7 @@ ZEND_API void zend_shutdown_executor_values(bool fast_shutdown)
|
||||
zval *zv;
|
||||
|
||||
EG(flags) |= EG_FLAGS_IN_RESOURCE_SHUTDOWN;
|
||||
zend_try {
|
||||
zend_close_rsrc_list(&EG(regular_list));
|
||||
} zend_end_try();
|
||||
zend_close_rsrc_list(&EG(regular_list));
|
||||
|
||||
/* No PHP callback functions should be called after this point. */
|
||||
EG(active) = 0;
|
||||
|
||||
@@ -217,15 +217,25 @@ void zend_close_rsrc_list(HashTable *ht)
|
||||
/* Reload ht->arData on each iteration, as it may be reallocated. */
|
||||
uint32_t i = ht->nNumUsed;
|
||||
|
||||
while (i-- > 0) {
|
||||
zval *p = ZEND_HASH_ELEMENT(ht, i);
|
||||
if (Z_TYPE_P(p) != IS_UNDEF) {
|
||||
zend_resource *res = Z_PTR_P(p);
|
||||
if (res->type >= 0) {
|
||||
zend_resource_dtor(res);
|
||||
retry:
|
||||
zend_try {
|
||||
while (i-- > 0) {
|
||||
zval *p = ZEND_HASH_ELEMENT(ht, i);
|
||||
if (Z_TYPE_P(p) != IS_UNDEF) {
|
||||
zend_resource *res = Z_PTR_P(p);
|
||||
if (res->type >= 0) {
|
||||
zend_resource_dtor(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} zend_catch {
|
||||
/* If we have bailed, we probably executed user code (e.g. user stream
|
||||
* API). Keep closing resources so they don't leak. User handlers must be
|
||||
* called now so they aren't called in zend_deactivate() on
|
||||
* zend_destroy_rsrc_list(&EG(regular_list)). At that point, the executor
|
||||
* has already shut down and the process would crash. */
|
||||
goto retry;
|
||||
} zend_end_try();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user