]> granicus.if.org Git - php/commitdiff
Fixed symlink("", "somthing") and link("", "somthing") in ZTS mode
authorDmitry Stogov <dmitry@php.net>
Tue, 10 Jul 2007 13:21:11 +0000 (13:21 +0000)
committerDmitry Stogov <dmitry@php.net>
Tue, 10 Jul 2007 13:21:11 +0000 (13:21 +0000)
TSRM/tsrm_virtual_cwd.c
ext/standard/link.c
ext/standard/tests/file/symlink_link_linkinfo_is_link_error1.phpt
main/fopen_wrappers.c

index 716fe77e8f6bfd7d927b7d2f745af50562875e80..c2bf2731c86727ddf70414f6500f168e144fb9cf 100644 (file)
@@ -477,11 +477,11 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
        int use_cache;
        int use_relative_path = 0;
        TSRMLS_FETCH();
-       
+
        use_cache = ((use_realpath != CWD_EXPAND) && CWDG(realpath_cache_size_limit));
 
        if (path_length == 0) 
-               return (0);
+               return (1);
        if (path_length >= MAXPATHLEN)
                return (1);
 
@@ -769,8 +769,23 @@ CWD_API char *virtual_realpath(const char *path, char *real_path TSRMLS_DC)
 {
        cwd_state new_state;
        char *retval;
+       char cwd[MAXPATHLEN];
 
-       CWD_STATE_COPY(&new_state, &CWDG(cwd));
+       /* realpath("") returns CWD */
+       if (!*path) {
+               new_state.cwd = (char*)malloc(1);
+               new_state.cwd[0] = '\0';
+               new_state.cwd_length = 0;               
+           if (VCWD_GETCWD(cwd, MAXPATHLEN)) {
+                   path = cwd;
+               }
+       } else if (!IS_ABSOLUTE_PATH(path, strlen(path))) {
+               CWD_STATE_COPY(&new_state, &CWDG(cwd));
+       } else {
+               new_state.cwd = (char*)malloc(1);
+               new_state.cwd[0] = '\0';
+               new_state.cwd_length = 0;               
+       }
        
        if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH)==0) {
                int len = new_state.cwd_length>MAXPATHLEN-1?MAXPATHLEN-1:new_state.cwd_length;
@@ -1202,7 +1217,15 @@ CWD_API char *tsrm_realpath(const char *path, char *real_path TSRMLS_DC)
        cwd_state new_state;
        char cwd[MAXPATHLEN];
 
-       if (!IS_ABSOLUTE_PATH(path, strlen(path)) &&
+       /* realpath("") returns CWD */
+       if (!*path) {
+               new_state.cwd = (char*)malloc(1);
+               new_state.cwd[0] = '\0';
+               new_state.cwd_length = 0;               
+           if (VCWD_GETCWD(cwd, MAXPATHLEN)) {
+                   path = cwd;
+               }
+       } else if (!IS_ABSOLUTE_PATH(path, strlen(path)) &&
            VCWD_GETCWD(cwd, MAXPATHLEN)) {
                new_state.cwd = strdup(cwd);
                new_state.cwd_length = strlen(cwd);
index af95c063b3bda357d33b01468a4de794aec6cb4d..ebda3100a4584f5e9fc315ea28094553a444e559 100644 (file)
@@ -123,6 +123,7 @@ PHP_FUNCTION(symlink)
        convert_to_string_ex(frompath);
 
        if (!expand_filepath(Z_STRVAL_PP(frompath), source_p TSRMLS_CC) || !expand_filepath(Z_STRVAL_PP(topath), dest_p TSRMLS_CC)) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory");
                RETURN_FALSE;
        }
 
@@ -179,6 +180,7 @@ PHP_FUNCTION(link)
        convert_to_string_ex(frompath);
 
        if (!expand_filepath(Z_STRVAL_PP(frompath), source_p TSRMLS_CC) || !expand_filepath(Z_STRVAL_PP(topath), dest_p TSRMLS_CC)) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory");
                RETURN_FALSE;
        }
 
index 80a8e41c65db5c498dd84cf8db15cb5d3b127adf..7c16188114248d33688125fb3032842d639e534d 100644 (file)
@@ -67,6 +67,7 @@ echo "Done\n";
 --CLEAN--
 <?php
 unlink(dirname(__FILE__)."/symlink_link_linkinfo_is_link_error1.tmp");
+@unlink(dirname(__FILE__)."/symlink_link_linkinfo_is_link_link_error1.tmp");
 ?>
 --EXPECTF--
 *** Testing symlink() for error conditions ***
index c27a60f1285d61e7be2636ea0ac23edc2bea34cd..63f608fb58e475c7b0abe0cfae74cb9f2d167887 100644 (file)
@@ -606,7 +606,9 @@ PHPAPI char *expand_filepath(const char *filepath, char *real_path TSRMLS_DC)
        char cwd[MAXPATHLEN];
        char *result;
 
-       if (IS_ABSOLUTE_PATH(filepath, strlen(filepath))) {
+       if (!filepath[0]) {
+               return NULL;
+       } else if (IS_ABSOLUTE_PATH(filepath, strlen(filepath))) {
                cwd[0] = '\0';
        } else{
                result = VCWD_GETCWD(cwd, MAXPATHLEN);