]> 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:09:24 +0000 (14:09 +0000)
committerFelipe Pena <felipe@php.net>
Tue, 22 Jul 2008 14:09:24 +0000 (14:09 +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 40f04b412daa9fc4d0c8d3aa0190b2fd4123956c..6bc27a8d82e8587dc8c3c59e9402e5d69cb8bf23 100644 (file)
@@ -856,6 +856,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;
@@ -885,6 +887,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);
 }
@@ -902,6 +906,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 dab4044ea9bad907620d9c55d0507ae0b2b5d0a8..195e36415717f1b8b62a0f78fdf27344f5ffc2eb 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 */
@@ -154,6 +155,8 @@ PHP_FUNCTION(stream_socket_client)
                RETURN_FALSE;
        }
        
+       stream->flags |= PHP_STREAM_FLAG_FCLOSE;
+       
        if (errstr) {
                efree(errstr);
        }
@@ -200,6 +203,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);
@@ -265,7 +270,9 @@ PHP_FUNCTION(stream_socket_accept)
                                NULL, NULL,
                                &tv, &errstr
                                TSRMLS_CC) && clistream) {
-
+               
+               clistream->flags |= PHP_STREAM_FLAG_FCLOSE;
+               
                if (peername) {
                        ZVAL_STRINGL(zpeername, peername, peername_len, 0);
                }
index 501b937815f43eeabbaddeae81453f3c97de122a..a46c1128799a01c7626c331ae461093343e4f58b 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 fb2fd0cd41a87b05e0adec9fe85e53b1fba8aea6..8025767bc18fc751b3f11f98f5d09d5996e2b295 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 4c551befc52b9704e6baebaa1f31be986028b7f3..a3809500a69dc8fa204d133b4cb969f5fd1e873b 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 c5b93e5d86110f0c7c34a7664e719d2f257b59f6..ce7083bc089455cf7cba12da6d4393c91f80931a 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 f6498128cce1f1b5082b6c94c1954ffa3dc92fe1..1f98bd8f42099f211710ae2c89ed5d70b4afe905 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 dff15309c01afc5bc9f3587326f5c51498003473..0d9cd9dd43a751bea38bb902e269ce108e496531 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 1591471ddfd603c9063e524180855544f149f59e..080ce98054d464b2800e5d2f2049fe1aed3e4420 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 cda93cb1a60321ac799f2a54dd0f5232b99e6575..7010571a42ea2bd9b382a93c99c78b78360b4538 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 5447c954a1a6a57f5b0e86aba9d50e92bf845e4e..6268d1b971ccfa61036e0d67ed4e9f8dcfb576d5 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 45c3944a7ac48bdda7b5349ee5c4ef268f32b3c4..6f6efb6dc501e11bb7df60be48cfd83dec97ff34 100644 (file)
@@ -501,6 +501,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 */