diff options
author | Dmitry Stogov <dmitry@php.net> | 2007-06-21 12:42:36 +0000 |
---|---|---|
committer | Dmitry Stogov <dmitry@php.net> | 2007-06-21 12:42:36 +0000 |
commit | 70105187dbe243c61d3d82cbafb0c33cffe4a7e5 (patch) | |
tree | 96dcf6ee0aa8093108c3c072a5ab7b633457faca /ext/standard/php_fopen_wrapper.c | |
parent | 5f82777275516804728b275d91777698dfb482c7 (diff) | |
download | php-git-70105187dbe243c61d3d82cbafb0c33cffe4a7e5.tar.gz |
Proper fix for bug #39215 Inappropriate close of stdin/stdout/stderr
Diffstat (limited to 'ext/standard/php_fopen_wrapper.c')
-rw-r--r-- | ext/standard/php_fopen_wrapper.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index 165b3f4124..52fb11f5a7 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; @@ -210,6 +211,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); @@ -222,6 +224,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); @@ -234,6 +237,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); @@ -285,10 +289,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; |