]> granicus.if.org Git - php/commitdiff
MFH: - Fixed bug #43137 (rmdir() and rename() do not clear statcache)
authorJani Taskinen <jani@php.net>
Wed, 31 Oct 2007 13:22:45 +0000 (13:22 +0000)
committerJani Taskinen <jani@php.net>
Wed, 31 Oct 2007 13:22:45 +0000 (13:22 +0000)
ext/openssl/openssl.c
ext/standard/filestat.c
ext/standard/php_filestat.h
ext/standard/tests/file/005_basic.phpt
ext/standard/tests/file/005_error.phpt
ext/standard/tests/file/bug43137.phpt [new file with mode: 0644]
main/streams/plain_wrapper.c

index 9998d2c1b8633de20d90fe4a088b36873b2b053c..433c885b518bb2bb1c14726e6f80f7e377ae40f0 100644 (file)
@@ -48,6 +48,9 @@
 #include <openssl/ssl.h>
 #include <openssl/pkcs12.h>
 
+/* Common */
+#include <time.h>
+
 #define DEFAULT_KEY_LENGTH     512
 #define MIN_KEY_LENGTH         384
 
@@ -1233,7 +1236,7 @@ static int check_cert(X509_STORE *ctx, X509 *x, STACK_OF(X509) *untrustedchain,
 }
 /* }}} */
 
-/* {{{ proto int openssl_x509_checkpurpose(mixed x509cert, int purpose, array cainfo [, string untrustedfile])
+/* {{{ proto mixed openssl_x509_checkpurpose(mixed x509cert, int purpose, array cainfo [, string untrustedfile])
    Checks the CERT to see if it can be used for the purpose in purpose. cainfo holds information about trusted CAs */
 PHP_FUNCTION(openssl_x509_checkpurpose)
 {
@@ -1244,10 +1247,9 @@ PHP_FUNCTION(openssl_x509_checkpurpose)
        STACK_OF(X509) * untrustedchain = NULL;
        long purpose;
        char * untrusted = NULL;
-       int untrusted_len;
+       int untrusted_len, ret;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zl|a!s", &zcert, &purpose, &zcainfo, &untrusted, &untrusted_len)
-                       == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zl|a!s", &zcert, &purpose, &zcainfo, &untrusted, &untrusted_len) == FAILURE) {
                return;
        }
 
@@ -1268,7 +1270,13 @@ PHP_FUNCTION(openssl_x509_checkpurpose)
        if (cert == NULL) {
                goto clean_exit;
        }
-       RETVAL_LONG(check_cert(cainfo, cert, untrustedchain, purpose));
+
+       ret = check_cert(cainfo, cert, untrustedchain, purpose);
+       if (ret != 0 && ret != 1) {
+               RETVAL_LONG(ret);
+       } else {
+               RETVAL_BOOL(ret);
+       }
 
 clean_exit:
        if (certresource == 1 && cert) {
index cfc364d2f4512859149b151f7e8602df25680e4e..31822375276419457057603b1be1f7713f089656 100644 (file)
@@ -698,14 +698,10 @@ PHP_FUNCTION(touch)
 /* }}} */
 #endif
 
-/* {{{ proto void clearstatcache(void)
-   Clear file stat cache */
-PHP_FUNCTION(clearstatcache)
+/* {{{ php_clear_stat_cache()
+*/
+PHPAPI void php_clear_stat_cache(TSRMLS_D)
 {
-       if (ZEND_NUM_ARGS()) {
-               WRONG_PARAM_COUNT;
-       }
-
        if (BG(CurrentStatFile)) {
                efree(BG(CurrentStatFile));
                BG(CurrentStatFile) = NULL;
@@ -718,6 +714,17 @@ PHP_FUNCTION(clearstatcache)
 }
 /* }}} */
 
+/* {{{ proto void clearstatcache(void)
+   Clear file stat cache */
+PHP_FUNCTION(clearstatcache)
+{
+       if (ZEND_NUM_ARGS()) {
+               WRONG_PARAM_COUNT;
+       }
+       php_clear_stat_cache(TSRMLS_C);
+}
+/* }}} */
+
 #define IS_LINK_OPERATION(__t) ((__t) == FS_TYPE || (__t) == FS_IS_LINK || (__t) == FS_LSTAT)
 #define IS_EXISTS_CHECK(__t) ((__t) == FS_EXISTS  || (__t) == FS_IS_W || (__t) == FS_IS_R || (__t) == FS_IS_X || (__t) == FS_IS_FILE || (__t) == FS_IS_DIR || (__t) == FS_IS_LINK)
 #define IS_ABLE_CHECK(__t) ((__t) == FS_IS_R || (__t) == FS_IS_W || (__t) == FS_IS_X)
index c8a8200d54c863763ce7c1f61b6a945174509253..3517af5cb73ca2371b4ebfd773b757e95b88d11c 100644 (file)
@@ -87,6 +87,7 @@ typedef unsigned int php_stat_len;
 typedef int php_stat_len;
 #endif
 
+PHPAPI void php_clear_stat_cache(TSRMLS_D);
 PHPAPI void php_stat(const char *filename, php_stat_len filename_length, int type, zval *return_value TSRMLS_DC);
 
 /* Switches for various filestat functions: */
index 44a49d8cd0648cd6a630ac90acd73805a10fe81d..5ed1118902f5329062957ac77b5bde749e278645 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-Test fileatime(),filemtime(),filectime() & touch() functions : basic functionality
+Test fileatime(), filemtime(), filectime() & touch() functions : basic functionality
 --FILE--
 <?php
 /*
index f5eff91315a2464d06f5f6fa2a73e69054d17c09..77fd4731c3cfc5a07699ec15d04d32ec0ee950d5 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-Test fileatime(), filemtime(), filectime() & touch() functions: error conditions 
+Test fileatime(), filemtime(), filectime() & touch() functions : error conditions 
 --FILE--
 <?php
 /*
diff --git a/ext/standard/tests/file/bug43137.phpt b/ext/standard/tests/file/bug43137.phpt
new file mode 100644 (file)
index 0000000..8125445
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+Bug #43137 (rmdir() and rename() do not clear statcache)
+--FILE--
+<?php
+       $toname = "TO_" . md5(microtime());
+       $dirname = "FROM_" . md5(microtime());
+
+       mkdir($dirname);
+       var_dump(is_dir($dirname)); // Expected: true
+       rename($dirname, $toname);
+       var_dump(is_dir($dirname)); // Expected: false
+       var_dump(is_dir($toname)); // Expected: true
+       rmdir($toname);
+       var_dump(is_dir($toname)); // Expected: false
+?>
+--EXPECT--
+bool(true)
+bool(false)
+bool(true)
+bool(false)
index 74c1841950b66346bccb17b42ec0cbb9e430bf53..438ba3aabd9c920c879b6742706c4006ac0d6d93 100644 (file)
@@ -24,6 +24,7 @@
 #include "php_open_temporary_file.h"
 #include "ext/standard/file.h"
 #include "ext/standard/flock_compat.h"
+#include "ext/standard/php_filestat.h"
 #include <stddef.h>
 #include <fcntl.h>
 #if HAVE_SYS_WAIT_H
@@ -1032,12 +1033,10 @@ static int php_plain_files_unlink(php_stream_wrapper *wrapper, char *url, int op
                }
                return 0;
        }
+
        /* Clear stat cache */
-       ZVAL_STRINGL(&funcname, "clearstatcache", sizeof("clearstatcache")-1, 0);
-       call_user_function_ex(CG(function_table), NULL, &funcname, &retval, 0, NULL, 0, NULL TSRMLS_CC);
-       if (retval) {
-               zval_ptr_dtor(&retval);
-       }
+       php_clear_stat_cache(TSRMLS_C);
+
        return 1;
 }
 
@@ -1107,6 +1106,9 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, c
         return 0;
        }
 
+       /* Clear stat cache */
+       php_clear_stat_cache(TSRMLS_C);
+
        return 1;
 }
 
@@ -1151,7 +1153,7 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod
                }
                else {
                        /* find a top level directory we need to create */
-                       while ( (p = strrchr(buf + offset, DEFAULT_SLASH)) || ( offset !=1 && (p = strrchr(buf, DEFAULT_SLASH))) ) {
+                       while ( (p = strrchr(buf + offset, DEFAULT_SLASH)) || (offset != 1 && (p = strrchr(buf, DEFAULT_SLASH))) ) {
                                int n = 0;
 
                                *p = '\0';
@@ -1218,6 +1220,9 @@ static int php_plain_files_rmdir(php_stream_wrapper *wrapper, char *url, int opt
                return 0;
        }
 
+       /* Clear stat cache */
+       php_clear_stat_cache(TSRMLS_C);
+
        return 1;
 }
 
@@ -1412,9 +1417,6 @@ stream_skip:
 }
 /* }}} */
 
-
-
-
 /*
  * Local variables:
  * tab-width: 4