Skip to content

Commit a8437d0

Browse files
committed
Fix GH-8827: Intentionally closing std handles no longer possible
We revert the commits which caused this regression from the PHP-8.0 and PHP-8.1 branches for now. We keep it in "master" because of PR #8833 which may offer a proper fix without BC break.
1 parent 6f87a5c commit a8437d0

File tree

4 files changed

+9
-28
lines changed

4 files changed

+9
-28
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ PHP NEWS
55
- Core:
66
. Fixed potential use after free in php_binary_init(). (Heiko Weber)
77

8+
- CLI:
9+
. Fixed GH-8827 (Intentionally closing std handles no longer possible). (cmb)
10+
811
- COM:
912
. Fixed bug GH-8778 (Integer arithmethic with large number variants fails).
1013
(cmb)

ext/zend_test/test.c

-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ ZEND_BEGIN_MODULE_GLOBALS(zend_test)
4242
int observer_show_opcode;
4343
int observer_nesting_depth;
4444
int replace_zend_execute_ex;
45-
zend_bool print_stderr_mshutdown;
4645
HashTable global_weakmap;
4746
ZEND_END_MODULE_GLOBALS(zend_test)
4847

@@ -408,7 +407,6 @@ PHP_INI_BEGIN()
408407
STD_PHP_INI_BOOLEAN("zend_test.observer.show_init_backtrace", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_show_init_backtrace, zend_zend_test_globals, zend_test_globals)
409408
STD_PHP_INI_BOOLEAN("zend_test.observer.show_opcode", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_show_opcode, zend_zend_test_globals, zend_test_globals)
410409
STD_PHP_INI_BOOLEAN("zend_test.replace_zend_execute_ex", "0", PHP_INI_SYSTEM, OnUpdateBool, replace_zend_execute_ex, zend_zend_test_globals, zend_test_globals)
411-
STD_PHP_INI_BOOLEAN("zend_test.print_stderr_mshutdown", "0", PHP_INI_SYSTEM, OnUpdateBool, print_stderr_mshutdown, zend_zend_test_globals, zend_test_globals)
412410
PHP_INI_END()
413411

414412
static zend_observer_fcall_handlers observer_fcall_init(zend_execute_data *execute_data);
@@ -528,10 +526,6 @@ PHP_MSHUTDOWN_FUNCTION(zend_test)
528526
UNREGISTER_INI_ENTRIES();
529527
}
530528

531-
if (ZT_G(print_stderr_mshutdown)) {
532-
fprintf(stderr, "[zend-test] MSHUTDOWN\n");
533-
}
534-
535529
return SUCCESS;
536530
}
537531

ext/zend_test/tests/gh8575.phpt

-14
This file was deleted.

sapi/cli/php_cli.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -539,21 +539,19 @@ static void cli_register_file_handles(void) /* {{{ */
539539
s_out = php_stream_open_wrapper_ex("php://stdout", "wb", 0, NULL, sc_out);
540540
s_err = php_stream_open_wrapper_ex("php://stderr", "wb", 0, NULL, sc_err);
541541

542-
/* Release stream resources, but don't free the underlying handles. Othewrise,
543-
* extensions which write to stderr or company during mshutdown/gshutdown
544-
* won't have the expected functionality.
545-
*/
546-
if (s_in) s_in->flags |= PHP_STREAM_FLAG_NO_CLOSE;
547-
if (s_out) s_out->flags |= PHP_STREAM_FLAG_NO_CLOSE;
548-
if (s_err) s_err->flags |= PHP_STREAM_FLAG_NO_CLOSE;
549-
550542
if (s_in==NULL || s_out==NULL || s_err==NULL) {
551543
if (s_in) php_stream_close(s_in);
552544
if (s_out) php_stream_close(s_out);
553545
if (s_err) php_stream_close(s_err);
554546
return;
555547
}
556548

549+
#if PHP_DEBUG
550+
/* do not close stdout and stderr */
551+
s_out->flags |= PHP_STREAM_FLAG_NO_CLOSE;
552+
s_err->flags |= PHP_STREAM_FLAG_NO_CLOSE;
553+
#endif
554+
557555
s_in_process = s_in;
558556

559557
php_stream_to_zval(s_in, &ic.value);

0 commit comments

Comments
 (0)