]> granicus.if.org Git - php/commitdiff
Readd fd 0-2 protection, so that users cannot close them
authorSascha Schumann <sas@php.net>
Tue, 13 May 2003 23:51:57 +0000 (23:51 +0000)
committerSascha Schumann <sas@php.net>
Tue, 13 May 2003 23:51:57 +0000 (23:51 +0000)
ext/standard/php_fopen_wrapper.c

index 87457e60e57218b68191acdee9eeec7ba4826576..1d1810b49f7690ea4e1bdd0cdfc131af3be542b1 100644 (file)
@@ -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 = {