From 0e47b9242de85736e7cc5f94d10b9b38b01b6707 Mon Sep 17 00:00:00 2001 From: Sascha Schumann Date: Tue, 13 May 2003 23:51:57 +0000 Subject: [PATCH] Readd fd 0-2 protection, so that users cannot close them --- ext/standard/php_fopen_wrapper.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 = { -- 2.50.1