diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2006-11-03 13:34:19 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2006-11-03 13:34:19 +0000 |
commit | bd2ab7bc1557153242f3efbfdeab1721b20ac614 (patch) | |
tree | cf9fbd5e2ab6ca8daad6a142c24bcdc9624c54bf /ext/standard/php_fopen_wrapper.c | |
parent | 3f71251ffa312a13fa81b9f42ae8e11e51894ea2 (diff) | |
download | php-git-bd2ab7bc1557153242f3efbfdeab1721b20ac614.tar.gz |
Fixed 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 | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index eafd3a3850..bcc33232c3 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -191,11 +191,41 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch } if (!strcasecmp(path, "stdin")) { - fd = !strcmp(sapi_module.name, "cli") ? STDIN_FILENO : dup(STDIN_FILENO); + if (!strcmp(sapi_module.name, "cli")) { + static int cli_in = 0; + fd = STDIN_FILENO; + if (cli_in) { + fd = dup(fd); + } else { + cli_in = 1; + } + } else { + fd = dup(STDIN_FILENO); + } } else if (!strcasecmp(path, "stdout")) { - fd = !strcmp(sapi_module.name, "cli") ? STDOUT_FILENO : dup(STDOUT_FILENO); + if (!strcmp(sapi_module.name, "cli")) { + static int cli_out = 0; + fd = STDOUT_FILENO; + if (cli_out++) { + fd = dup(fd); + } else { + cli_out = 1; + } + } else { + fd = dup(STDOUT_FILENO); + } } else if (!strcasecmp(path, "stderr")) { - fd = !strcmp(sapi_module.name, "cli") ? STDERR_FILENO : dup(STDERR_FILENO); + if (!strcmp(sapi_module.name, "cli")) { + static int cli_err = 0; + fd = STDERR_FILENO; + if (cli_err++) { + fd = dup(fd); + } else { + cli_err = 1; + } + } else { + fd = dup(STDERR_FILENO); + } } else if (!strncasecmp(path, "filter/", 7)) { /* Save time/memory when chain isn't specified */ if (strchr(mode, 'r') || strchr(mode, '+')) { |