Skip to content

Commit b8dee9b

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix GH-8827: Intentionally closing std handles no longer possible
2 parents 080fde2 + a8437d0 commit b8dee9b

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ PHP NEWS
1111
references). (Nicolas Grekas)
1212
. Fixed potential use after free in php_binary_init(). (Heiko Weber)
1313

14+
- CLI:
15+
. Fixed GH-8827 (Intentionally closing std handles no longer possible). (cmb)
16+
1417
- COM:
1518
. Fixed bug GH-8778 (Integer arithmethic with large number variants fails).
1619
(cmb)

ext/zend_test/php_test.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ ZEND_BEGIN_MODULE_GLOBALS(zend_test)
5151
HashTable global_weakmap;
5252
int replace_zend_execute_ex;
5353
int register_passes;
54-
bool print_stderr_mshutdown;
5554
zend_test_fiber *active_fiber;
5655
ZEND_END_MODULE_GLOBALS(zend_test)
5756

ext/zend_test/tests/gh8575.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
--TEST--
22
CLI: stderr is available in mshutdown
33
--SKIPIF--
4-
<?php if (php_sapi_name() != "cli") die('skip cli test only'); ?>
5-
--EXTENSIONS--
6-
zend_test
4+
<?php
5+
if (!extension_loaded('zend-test')) die('skip zend-test extension required');
6+
if (php_sapi_name() != "cli") die('skip cli test only');
7+
?>
78
--INI--
89
zend_test.print_stderr_mshutdown=1
910
--FILE--

sapi/cli/php_cli.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,9 @@ static void cli_register_file_handles(bool no_close) /* {{{ */
542542
* extensions which write to stderr or company during mshutdown/gshutdown
543543
* won't have the expected functionality.
544544
*/
545-
if (no_close) {
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-
}
545+
if (s_in) s_in->flags |= PHP_STREAM_FLAG_NO_CLOSE;
546+
if (s_out) s_out->flags |= PHP_STREAM_FLAG_NO_CLOSE;
547+
if (s_err) s_err->flags |= PHP_STREAM_FLAG_NO_CLOSE;
550548

551549
if (s_in==NULL || s_out==NULL || s_err==NULL) {
552550
if (s_in) php_stream_close(s_in);
@@ -960,7 +958,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
960958
switch (behavior) {
961959
case PHP_MODE_STANDARD:
962960
if (script_file) {
963-
cli_register_file_handles(/* no_close */ true);
961+
cli_register_file_handles(/* no_close */ PHP_DEBUG || num_repeats > 1);
964962
}
965963

966964
if (interactive) {
@@ -995,7 +993,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
995993
}
996994
break;
997995
case PHP_MODE_CLI_DIRECT:
998-
cli_register_file_handles(/* no_close */ true);
996+
cli_register_file_handles(/* no_close */ PHP_DEBUG || num_repeats > 1);
999997
zend_eval_string_ex(exec_direct, NULL, "Command line code", 1);
1000998
break;
1001999

@@ -1010,7 +1008,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
10101008
file_handle.filename = NULL;
10111009
}
10121010

1013-
cli_register_file_handles(/* no_close */ true);
1011+
cli_register_file_handles(/* no_close */ PHP_DEBUG || num_repeats > 1);
10141012

10151013
if (exec_begin) {
10161014
zend_eval_string_ex(exec_begin, NULL, "Command line begin code", 1);

0 commit comments

Comments
 (0)