From: Dmitry Stogov Date: Thu, 21 Jun 2007 12:42:58 +0000 (+0000) Subject: Proper fix for bug #39215 Inappropriate close of stdin/stdout/stderr X-Git-Tag: BEFORE_IMPORT_OF_MYSQLND~410 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c8acfd843ee2f562247884f6ded728437b30589e;p=php Proper fix for bug #39215 Inappropriate close of stdin/stdout/stderr --- diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index ea1861b28f..0ba6303156 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -159,6 +159,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch php_stream * stream = NULL; char *p, *token, *pathdup; long max_memory; + FILE *file = NULL; if (!strncasecmp(path, "php://", 6)) { path += 6; @@ -212,6 +213,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch fd = dup(fd); } else { cli_in = 1; + file = stdin; } } else { fd = dup(STDIN_FILENO); @@ -224,6 +226,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch fd = dup(fd); } else { cli_out = 1; + file = stdout; } } else { fd = dup(STDOUT_FILENO); @@ -236,6 +239,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch fd = dup(fd); } else { cli_err = 1; + file = stderr; } } else { fd = dup(STDERR_FILENO); @@ -287,10 +291,14 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch /* failed to dup */ return NULL; } - - stream = php_stream_fopen_from_fd(fd, mode, NULL); - if (stream == NULL) { - close(fd); + + if (file) { + stream = php_stream_fopen_from_file(file, mode); + } else { + stream = php_stream_fopen_from_fd(fd, mode, NULL); + if (stream == NULL) { + close(fd); + } } return stream;