From: Sascha Schumann Date: Tue, 13 May 2003 23:51:57 +0000 (+0000) Subject: Readd fd 0-2 protection, so that users cannot close them X-Git-Tag: php-4.3.2RC3~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e47b9242de85736e7cc5f94d10b9b38b01b6707;p=php Readd fd 0-2 protection, so that users cannot close them --- diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index 87457e60e5..1d1810b49f 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -124,6 +124,7 @@ php_stream_ops php_stream_input_ops = { php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { int fd = -1; + php_stream *stream = NULL; if (!strncasecmp(path, "php://", 6)) path += 6; @@ -145,9 +146,13 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch } if (fd != -1) { - return php_stream_fopen_from_fd(fd, mode, NULL); + int nfd = dup(fd); + + stream = php_stream_fopen_from_fd(nfd, mode, NULL); + + if (!stream) close(nfd); } - return NULL; + return stream; } static php_stream_wrapper_ops php_stdio_wops = {