Index: main/php_open_temporary_file.c =================================================================== RCS file: /repository/php-src/main/php_open_temporary_file.c,v retrieving revision 1.34.2.1.2.9 diff -u -p -d -a -r1.34.2.1.2.9 php_open_temporary_file.c --- main/php_open_temporary_file.c 21 Jul 2007 01:43:33 -0000 1.34.2.1.2.9 +++ main/php_open_temporary_file.c 10 Aug 2007 10:00:10 -0000 @@ -98,6 +98,8 @@ static int php_do_open_temporary_file(co { char *trailing_slash; char *opened_path; + char cwd[MAXPATHLEN]; + cwd_state new_state; int path_len = 0; int fd = -1; #ifndef HAVE_MKSTEMP @@ -108,25 +110,36 @@ static int php_do_open_temporary_file(co ; #endif - if (!path) { + if (!path || !path[0]) { return -1; } - path_len = strlen(path); + if (!VCWD_GETCWD(cwd, MAXPATHLEN)) { + cwd[0] = '\0'; + } - if (!path_len || IS_SLASH(path[path_len - 1])) { + new_state.cwd = strdup(cwd); + new_state.cwd_length = strlen(cwd); + + if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH)) { + free(new_state.cwd); + return -1; + } + + if (IS_SLASH(new_state.cwd[new_state.cwd_length - 1])) { trailing_slash = ""; } else { trailing_slash = "/"; } - if (spprintf(&opened_path, 0, "%s%s%sXXXXXX", path, trailing_slash, pfx) >= MAXPATHLEN) { + if (spprintf(&opened_path, 0, "%s%s%sXXXXXX", new_state.cwd, trailing_slash, pfx) >= MAXPATHLEN) { efree(opened_path); + free(new_state.cwd); return -1; } #ifdef PHP_WIN32 - if (GetTempFileName(path, pfx, 0, opened_path)) { + if (GetTempFileName(new_state.cwd, pfx, 0, opened_path)) { /* Some versions of windows set the temp file to be read-only, * which means that opening it will fail... */ VCWD_CHMOD(opened_path, 0600); @@ -144,6 +157,7 @@ static int php_do_open_temporary_file(co } else { *opened_path_p = opened_path; } + free(new_state.cwd); return fd; } /* }}} */