Re: [ZEND-ENGINE-CVS] cvs: TSRM(PHP_5_2) / tsrm_virtual_cwd.c tsrm_virtual_cwd.h php-src NEWS

From: Date: Fri, 10 Nov 2006 15:00:59 +0000
Subject: Re: [ZEND-ENGINE-CVS] cvs: TSRM(PHP_5_2) / tsrm_virtual_cwd.c tsrm_virtual_cwd.h php-src NEWS
References: 1  Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-5385@lists.php.net to get a copy of this message
Hi Dmitry This patch breaks realpath() on at least BSD (non-ZTS); php -r 'var_dump(realpath("/this/is/a/bogus/path"));' string(21) "/this/is/a/bogus/path" -Hannes On 11/10/06, Dmitry Stogov <dmitry@php.net> wrote:
dmitry          Fri Nov 10 12:59:27 2006 UTC
  Modified files:              (Branch: PHP_5_2)
    /php-src    NEWS
    /TSRM       tsrm_virtual_cwd.c tsrm_virtual_cwd.h
Log: VCWD_REALPATH() is improved to use realpath cache without VIRTUAL_DIR http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.350&r2=1.2027.2.547.2.351&diff_format=u Index: php-src/NEWS diff -u php-src/NEWS:1.2027.2.547.2.350 php-src/NEWS:1.2027.2.547.2.351
--- php-src/NEWS:1.2027.2.547.2.350     Fri Nov 10 12:02:09 2006
+++ php-src/NEWS        Fri Nov 10 12:59:27 2006
@@ -9,6 +9,8 @@
     In case of modification of corresponding registry-tree PHP will reload
     it automatic
. start timiout thread only if necessary +- VCWD_REALPATH() is improved to use realpath cache without VIRTUAL_DIR. + (Dmitry) - ext/bcmath intialization code is moved from request startup to module startup. (Dmitry) - Zend Memory Manager Improvements (Dmitry) http://cvs.php.net/viewvc.cgi/TSRM/tsrm_virtual_cwd.c?r1=1.74.2.9.2.9&r2=1.74.2.9.2.10&diff_format=u Index: TSRM/tsrm_virtual_cwd.c diff -u TSRM/tsrm_virtual_cwd.c:1.74.2.9.2.9 TSRM/tsrm_virtual_cwd.c:1.74.2.9.2.10
--- TSRM/tsrm_virtual_cwd.c:1.74.2.9.2.9        Fri Oct  6 14:03:19 2006
+++ TSRM/tsrm_virtual_cwd.c     Fri Nov 10 12:59:27 2006
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
*/ -/* $Id: tsrm_virtual_cwd.c,v 1.74.2.9.2.9 2006/10/06 14:03:19 tony2001 Exp $ */ +/* $Id: tsrm_virtual_cwd.c,v 1.74.2.9.2.10 2006/11/10 12:59:27 dmitry Exp $ */ #include <sys/types.h> #include <sys/stat.h> @@ -1033,25 +1033,36 @@ #endif -/* On AIX & Tru64 when a file does not exist realpath() returns - * NULL, and sets errno to ENOENT. Unlike in other libc implementations - * the destination is not filled and remains undefined. Therefor, we - * must populate it manually using strcpy as done on systems with no - * realpath() function. - */ -#if defined(__osf__) || defined(_AIX) -char *php_realpath_hack(const char *src, char *dest) +CWD_API char *tsrm_realpath(const char *path, char *real_path TSRMLS_DC) {
-       char *ret;
+       cwd_state new_state;
+       char cwd[MAXPATHLEN];
-       if ((ret = realpath(src, dest)) == NULL && errno == ENOENT) {
-               return strcpy(dest, src);
+       if (!IS_ABSOLUTE_PATH(path, strlen(path)) &&
+           VCWD_GETCWD(cwd, MAXPATHLEN)) {
+               new_state.cwd = strdup(cwd);
+               new_state.cwd_length = strlen(cwd);
        } else {
-               return ret;
+               new_state.cwd = (char*)malloc(1);
+               new_state.cwd[0] = '\0';
+               new_state.cwd_length = 0;
+       }
+
+       if (virtual_file_ex(&new_state, path, NULL, 1)) {
+               free(new_state.cwd);
+               return NULL;
        }
-} -#endif
+       if (real_path) {
+               int copy_len = new_state.cwd_length>MAXPATHLEN-1 ? MAXPATHLEN-1 : new_state.cwd_length;
+               memcpy(real_path, new_state.cwd, copy_len);
+               real_path[copy_len] = '\0';
+               free(new_state.cwd);
+               return real_path;
+       } else {
+               return new_state.cwd;
+       }
+} /* http://cvs.php.net/viewvc.cgi/TSRM/tsrm_virtual_cwd.h?r1=1.48.2.5.2.2&r2=1.48.2.5.2.3&diff_format=u Index: TSRM/tsrm_virtual_cwd.h diff -u TSRM/tsrm_virtual_cwd.h:1.48.2.5.2.2 TSRM/tsrm_virtual_cwd.h:1.48.2.5.2.3
--- TSRM/tsrm_virtual_cwd.h:1.48.2.5.2.2        Wed Oct  4 13:24:19 2006
+++ TSRM/tsrm_virtual_cwd.h     Fri Nov 10 12:59:27 2006
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
*/ -/* $Id: tsrm_virtual_cwd.h,v 1.48.2.5.2.2 2006/10/04 13:24:19 tony2001 Exp $ */ +/* $Id: tsrm_virtual_cwd.h,v 1.48.2.5.2.3 2006/11/10 12:59:27 dmitry Exp $ */ #ifndef VIRTUAL_CWD_H #define VIRTUAL_CWD_H @@ -172,10 +172,6 @@ #endif #endif -#if defined(__osf__) || defined(_AIX) -char *php_realpath_hack(const char *src, char *dest); -#endif - #if HAVE_UTIME CWD_API int virtual_utime(const char *filename, struct utimbuf *buf TSRMLS_DC); #endif @@ -186,6 +182,8 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath); +CWD_API char *tsrm_realpath(const char *path, char *real_path TSRMLS_DC); + #define REALPATH_CACHE_TTL (2*60) /* 2 minutes */
 #define REALPATH_CACHE_SIZE 0      /* disabled while php.ini isn't loaded */
@@ -278,15 +276,7 @@ #define VCWD_ACCESS(pathname, mode) access(pathname, mode) #endif -#ifdef HAVE_REALPATH -#if defined(__osf__) || defined(_AIX) -#define VCWD_REALPATH(path, real_path) php_realpath_hack(path, real_path) -#else -#define VCWD_REALPATH(path, real_path) realpath(path, real_path) -#endif -#else -#define VCWD_REALPATH(path, real_path) strcpy(real_path, path) -#endif +#define VCWD_REALPATH(path, real_path) tsrm_realpath(path, real_path TSRMLS_CC) #if HAVE_UTIME #define VCWD_UTIME(path, time) utime(path, time) -- Zend Engine CVS Mailing List (http://cvs.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.zend-engine.cvs (#5385) next »