]> granicus.if.org Git - php/commitdiff
- MFH: Fixed bug #44246 (closedir() accepts a file resource opened by fopen())
authorFelipe Pena <felipe@php.net>
Tue, 22 Jul 2008 14:11:25 +0000 (14:11 +0000)
committerFelipe Pena <felipe@php.net>
Tue, 22 Jul 2008 14:11:25 +0000 (14:11 +0000)
14 files changed:
ext/standard/file.c
ext/standard/fsock.c
ext/standard/proc_open.c
ext/standard/streamsfuncs.c
ext/standard/tests/file/fscanf_variation10.phpt
ext/standard/tests/file/fscanf_variation16.phpt
ext/standard/tests/file/fscanf_variation22.phpt
ext/standard/tests/file/fscanf_variation29.phpt
ext/standard/tests/file/fscanf_variation35.phpt
ext/standard/tests/file/fscanf_variation4.phpt
ext/standard/tests/file/fscanf_variation41.phpt
ext/standard/tests/file/fscanf_variation47.phpt
main/php_streams.h
sapi/cli/php_cli.c

index 485741e4e02ab6660dfed54ba3b11a1fafe6e587..44c64d8cde54dae3efcd36d032529616b5dccc81 100644 (file)
@@ -861,6 +861,8 @@ PHP_NAMED_FUNCTION(php_if_tmpfile)
        stream = php_stream_fopen_tmpfile();
 
        if (stream) {
+               stream->flags |= PHP_STREAM_FLAG_FCLOSE;
+
                php_stream_to_zval(stream, return_value);
        } else {
                RETURN_FALSE;
@@ -891,6 +893,8 @@ PHP_NAMED_FUNCTION(php_if_fopen)
        if (stream == NULL) {
                RETURN_FALSE;
        }
+       
+       stream->flags |= PHP_STREAM_FLAG_FCLOSE;
 
        php_stream_to_zval(stream, return_value);
 
@@ -912,6 +916,12 @@ PHPAPI PHP_FUNCTION(fclose)
        }
 
        PHP_STREAM_TO_ZVAL(stream, arg1);
+       
+       if (!(stream->flags & PHP_STREAM_FLAG_FCLOSE)) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a valid stream resource", stream->rsrc_id);
+               RETURN_FALSE;
+       }
+       
        if (!stream->is_persistent) {
                zend_list_delete(stream->rsrc_id);
        } else {
index 31774f554cfa8624a583db30634388e3c2ec4fe7..7fd30f80c00f91d12b6cbed3402b51ef4c986fb3 100644 (file)
@@ -79,6 +79,8 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent)
        stream = php_stream_xport_create(hostname, hostname_len, ENFORCE_SAFE_MODE | REPORT_ERRORS,
                        STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, hashkey, &tv, NULL, &errstr, &err);
 
+       stream->flags |= PHP_STREAM_FLAG_FCLOSE;
+
        if (port > 0) {
                efree(hostname);
        }
index cd4c7b70e0e74ffe8adab983b37dd92677dec519..f6f469a54a76e07f212768519d2c9ba81f2fb900 100644 (file)
@@ -969,7 +969,7 @@ PHP_FUNCTION(proc_open)
                                        zval *retfp;
 
                                        /* nasty hack; don't copy it */
-                                       stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
+                                       stream->flags |= PHP_STREAM_FLAG_NO_SEEK | PHP_STREAM_FLAG_FCLOSE;
                                        
                                        MAKE_STD_ZVAL(retfp);
                                        php_stream_to_zval(stream, retfp);
index 60560314ee8ed5d2a2d144e26031dc9276b08697..465ad90e6611a82481a4ef53dd3746ed70bbfdef 100644 (file)
@@ -122,6 +122,7 @@ PHP_FUNCTION(stream_socket_client)
                        STREAM_XPORT_CLIENT | (flags & PHP_STREAM_CLIENT_CONNECT ? STREAM_XPORT_CONNECT : 0) |
                        (flags & PHP_STREAM_CLIENT_ASYNC_CONNECT ? STREAM_XPORT_CONNECT_ASYNC : 0),
                        hashkey, &tv, context, &errstr, &err);
+               
 
        if (stream == NULL) {
                /* host might contain binary characters */
@@ -150,6 +151,8 @@ PHP_FUNCTION(stream_socket_client)
                RETURN_FALSE;
        }
        
+       stream->flags |= PHP_STREAM_FLAG_FCLOSE;
+       
        if (errstr) {
                efree(errstr);
        }
@@ -195,6 +198,8 @@ PHP_FUNCTION(stream_socket_server)
        stream = php_stream_xport_create(host, host_len, ENFORCE_SAFE_MODE | REPORT_ERRORS,
                        STREAM_XPORT_SERVER | flags,
                        NULL, NULL, context, &errstr, &err);
+                       
+       stream->flags |= PHP_STREAM_FLAG_FCLOSE;
 
        if (stream == NULL) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s (%s)", host, errstr == NULL ? "Unknown error" : errstr);
@@ -262,7 +267,9 @@ PHP_FUNCTION(stream_socket_accept)
                                NULL, NULL,
                                &tv, &errstr
                                TSRMLS_CC) && clistream) {
-
+               
+               clistream->flags |= PHP_STREAM_FLAG_FCLOSE;
+               
                if (peername) {
                        Z_TYPE_P(peername) = IS_STRING;
                }
index 0222becac3f5c2e8c6f220cad6e56ff9685841fb..a9109e67f6beea44e99f07c8aea41d10b4cbea90 100644 (file)
@@ -68,7 +68,7 @@ foreach($float_formats as $float_format) {
 
 // closing the resources
 fclose($fp);
-fclose($dfp);
+closedir($dfp);
 
 echo "\n*** Done ***";
 ?>
index 1312c18de7a8e5d4728a5df4f9e58346a26b9d32..94009248c4961c859ab225017ce7ee2833ce5bc4 100644 (file)
@@ -67,7 +67,7 @@ foreach($string_formats as $string_format) {
 
 // closing the resources
 fclose($fp);
-fclose($dfp);
+closedir($dfp);
 
 echo "\n*** Done ***";
 ?>
index d43226a4f3af0d969cef268a0cd4c9a45231adf7..8fa62deb444d773a30b56dd35214b62bd1d3e859 100644 (file)
@@ -67,7 +67,7 @@ foreach($char_formats as $char_format) {
 
 // closing the resources
 fclose($fp);
-fclose($dfp);
+closedir($dfp);
 
 echo "\n*** Done ***";
 ?>
index 89f82e97d0985e22c90809a2bd487d943861e6f7..b6752765fa4de72625d7173c2ed7499a60237be5 100644 (file)
@@ -68,7 +68,7 @@ foreach($octal_formats as $octal_format) {
 
 // closing the resources
 fclose($fp);
-fclose($dfp);
+closedir($dfp);
 
 echo "\n*** Done ***";
 ?>
index d259f12d4b21ac44ac0318a1d0e4f4a8c4f7a0c9..af0266d1a68432fd44018ec2ee98a23c57579944 100644 (file)
@@ -63,7 +63,7 @@ foreach($hexa_formats as $hexa_format) {
 
 // closing the resources
 fclose($fp);
-fclose($dfp);
+closedir($dfp);
 
 echo "\n*** Done ***";
 ?>
index 591836dffd78d3338ab8c194537d3a1f1103d33c..a7e83a96e663e5765a79d84174ea4242cf73a8ed 100644 (file)
@@ -64,7 +64,7 @@ foreach($int_formats as $int_format) {
 
 // closing the resources
 fclose($fp);
-fclose($dfp);
+closedir($dfp);
 
 echo "\n*** Done ***";
 ?>
index 76faf0b09ef0327e999b6f5aedee3d946077ab8b..a1d11c13305f6cf64a8eaaad903543e95963373b 100644 (file)
@@ -63,7 +63,7 @@ foreach($unsigned_formats as $unsigned_format) {
 
 // closing the resources
 fclose($fp);
-fclose($dfp);
+closedir($dfp);
 
 echo "\n*** Done ***";
 ?>
index 011169a5c3ed6e74c23207594f68ccbc2d88cd38..183ee7a82223860d2ea5fc00ff60e3d3a03c2f20 100644 (file)
@@ -63,7 +63,7 @@ foreach($scientific_formats as $scientific_format) {
 
 // closing the resources
 fclose($fp);
-fclose($dfp);
+closedir($dfp);
 
 echo "\n*** Done ***";
 ?>
index 455c2c8505fd4be18cbe77721b8d245b88673deb..bfb65ae5367dad5f3a6e1ed987434d41413b67e8 100755 (executable)
@@ -183,6 +183,8 @@ struct _php_stream_wrapper  {
        
 #define PHP_STREAM_FLAG_IS_DIR                                         64
 
+#define PHP_STREAM_FLAG_FCLOSE                                         128
+
 struct _php_stream  {
        php_stream_ops *ops;
        void *abstract;                 /* convenience pointer for abstraction */
index 5e5bb6015d6ad81196f7269a71c52e3ee7b75363..f8c84e8627180df0375bcdba396aef3b7b19e9b3 100644 (file)
@@ -504,6 +504,10 @@ static void cli_register_file_handles(TSRMLS_D) /* {{{ */
                if (s_err) php_stream_close(s_err);
                return;
        }
+       
+       s_in->flags  |= PHP_STREAM_FLAG_FCLOSE;
+       s_out->flags |= PHP_STREAM_FLAG_FCLOSE;
+       s_err->flags |= PHP_STREAM_FLAG_FCLOSE;
 
 #if PHP_DEBUG
        /* do not close stdout and stderr */