Skip to content

Commit c53c3e2

Browse files
morrisonleviarnaud-lb
authored andcommitted
Stop closing stderr and stdout streams (#8571)
Extensions may (and do) write to stderr in mshutdown and similar. In the best case, with the stderr stream closed, it's just swallowed. However, some libraries will do things like try to detect color, and these will outright fail and cause an error path to be taken.
1 parent 980385d commit c53c3e2

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

sapi/cli/php_cli.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ static void php_cli_usage(char *argv0)
526526

527527
static php_stream *s_in_process = NULL;
528528

529-
static void cli_register_file_handles(bool no_close) /* {{{ */
529+
static void cli_register_file_handles(void) /* {{{ */
530530
{
531531
php_stream *s_in, *s_out, *s_err;
532532
php_stream_context *sc_in=NULL, *sc_out=NULL, *sc_err=NULL;
@@ -540,11 +540,9 @@ static void cli_register_file_handles(bool no_close) /* {{{ */
540540
* extensions which write to stderr or company during mshutdown/gshutdown
541541
* won't have the expected functionality.
542542
*/
543-
if (no_close) {
544-
if (s_in) s_in->flags |= PHP_STREAM_FLAG_NO_CLOSE;
545-
if (s_out) s_out->flags |= PHP_STREAM_FLAG_NO_CLOSE;
546-
if (s_err) s_err->flags |= PHP_STREAM_FLAG_NO_CLOSE;
547-
}
543+
if (s_in) s_in->flags |= PHP_STREAM_FLAG_NO_CLOSE;
544+
if (s_out) s_out->flags |= PHP_STREAM_FLAG_NO_CLOSE;
545+
if (s_err) s_err->flags |= PHP_STREAM_FLAG_NO_CLOSE;
548546

549547
if (s_in==NULL || s_out==NULL || s_err==NULL) {
550548
if (s_in) php_stream_close(s_in);
@@ -958,7 +956,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
958956
switch (behavior) {
959957
case PHP_MODE_STANDARD:
960958
if (script_file) {
961-
cli_register_file_handles(/* no_close */ true);
959+
cli_register_file_handles();
962960
}
963961

964962
if (interactive) {
@@ -993,7 +991,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
993991
}
994992
break;
995993
case PHP_MODE_CLI_DIRECT:
996-
cli_register_file_handles(/* no_close */ true);
994+
cli_register_file_handles();
997995
zend_eval_string_ex(exec_direct, NULL, "Command line code", 1);
998996
break;
999997

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

1011-
cli_register_file_handles(/* no_close */ true);
1009+
cli_register_file_handles();
10121010

10131011
if (exec_begin) {
10141012
zend_eval_string_ex(exec_begin, NULL, "Command line begin code", 1);

0 commit comments

Comments
 (0)