]> granicus.if.org Git - php/commitdiff
- Fixed bug #44246 (closedir() accepts a file resource opened by fopen())
authorFelipe Pena <felipe@php.net>
Tue, 22 Jul 2008 14:06:17 +0000 (14:06 +0000)
committerFelipe Pena <felipe@php.net>
Tue, 22 Jul 2008 14:06:17 +0000 (14:06 +0000)
15 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
ext/standard/tests/strings/sprintf_variation23.phpt
main/php_streams.h
sapi/cli/php_cli.c

index 26a99257059d23c50e9cac8f95532276119d99f7..b7e807b16314d51739b5096104ba1e2c2d3e642a 100644 (file)
@@ -965,6 +965,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;
@@ -998,6 +1000,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);
 }
@@ -1015,6 +1019,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 1dc2215666c5999ee21ba8f3669c07d926fde153..84ed477a0e2162293d26ac7732d52ed5229158ff 100644 (file)
@@ -79,6 +79,8 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent)
        stream = php_stream_xport_create(hostname, hostname_len, 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 67dd956fa1b965bbf3074285c16b848d9f0adbf1..0ae8d9c21152136e3a92536a79ff0db0a9206844 100644 (file)
@@ -971,7 +971,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;
 
                                        if (UG(unicode) && !binary_pipes) {
                                                if (write_stream) {
index a0a7245b09374ea5003f6743d66d225a0ca53cf8..521ed3d024ad86dfcf5e8e8f2a082e973c2c88e6 100644 (file)
@@ -126,6 +126,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 */
@@ -155,6 +156,8 @@ PHP_FUNCTION(stream_socket_client)
                RETURN_FALSE;
        }
        
+       stream->flags |= PHP_STREAM_FLAG_FCLOSE;
+       
        if (errstr) {
                efree(errstr);
        }
@@ -201,6 +204,8 @@ PHP_FUNCTION(stream_socket_server)
        stream = php_stream_xport_create(host, host_len, 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);
@@ -267,7 +272,9 @@ PHP_FUNCTION(stream_socket_accept)
                                NULL, NULL,
                                &tv, &errstr
                                TSRMLS_CC) && clistream) {
-
+               
+               clistream->flags |= PHP_STREAM_FLAG_FCLOSE;
+               
                if (peername) {
                        ZVAL_RT_STRINGL(zpeername, peername, peername_len, ZSTR_AUTOFREE);
                }
index 8cd7e32be9093d8356a097ae75f85239e4df4c0d..d33bd56df0e704769a91634676d7812d564aaf6f 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 edc742269935090ac0712a53d2976395bb8d6749..8b82223138d5579f1434f86e266de44f9c5c7b26 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 03af8494bca13e95462bba312244f8e2dfb5cecb..599acd8ddffde0997575f1ae2b74cb8041df09d0 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 498048cff35ce4fd406eb3e462e93aecd752cd3a..78b0e3dc2fc3a63d43ed70c8941d5ced4c552c68 100644 (file)
@@ -39,7 +39,7 @@ foreach($resource_values as $resource_value) {
 
 // closing the resources
 fclose($fp);
-fclose($dfp);
+closedir($dfp);
 
 echo "Done";
 ?>
index 4368aa8a292b9d4fa3be8249123df6abebe13e09..fcffeafeddbd6553806d0a3e8c44a82f048377e3 100755 (executable)
@@ -191,6 +191,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 7bca968aefcbd6d6b3af2ad520562457405294e7..ccac5166ec02b6420dc3b63ed639dcc70817f8b3 100644 (file)
@@ -516,6 +516,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 */