[Pkg-php-commits] r1228 - php5/trunk/debian/patches

Sean Finney seanius at alioth.debian.org
Thu Jan 22 21:59:01 UTC 2009


Author: seanius
Date: 2009-01-22 21:59:00 +0000 (Thu, 22 Jan 2009)
New Revision: 1228

Modified:
   php5/trunk/debian/patches/CVE-2008-5658.patch
Log:
updated with proposed patch from pierre

Modified: php5/trunk/debian/patches/CVE-2008-5658.patch
===================================================================
--- php5/trunk/debian/patches/CVE-2008-5658.patch	2009-01-20 23:10:50 UTC (rev 1227)
+++ php5/trunk/debian/patches/CVE-2008-5658.patch	2009-01-22 21:59:00 UTC (rev 1228)
@@ -1,9 +1,307 @@
 --- php5-5.2.6.dfsg.1.orig/ext/zip/php_zip.c
 +++ php5-5.2.6.dfsg.1/ext/zip/php_zip.c
-@@ -82,6 +82,46 @@ static int le_zip_entry;
+@@ -82,6 +82,344 @@ static int le_zip_entry;
  
  /* }}} */
  
++static int php_zip_realpath_r(char *path, int start, int len, int *ll, time_t *t, int use_realpath, int is_dir, int *link_is_dir TSRMLS_DC) /* {{{ */
++{
++	int i, j;
++	int directory = 0;
++#ifdef PHP_WIN32
++	WIN32_FIND_DATA data;
++	HANDLE hFind;
++#else
++	struct stat st;
++#endif
++	realpath_cache_bucket *bucket;
++	char *tmp;
++
++	while (1) {
++		if (len <= start) {
++			return start;
++		}
++
++		i = len;
++		while (i > start && !IS_SLASH(path[i-1])) {
++			i--;
++		}
++
++		if (i == len ||
++			(i == len - 1 && path[i] == '.')) {
++			/* remove double slashes and '.' */
++			len = i - 1;
++			is_dir = 1;
++			continue;
++		} else if (i == len - 2 && path[i] == '.' && path[i+1] == '.') {
++			/* remove '..' and previous directory */
++			if (i - 1 <= start) {
++				return start ? start : len;
++			}
++			j = php_zip_realpath_r(path, start, i-1, ll, t, use_realpath, 1, NULL TSRMLS_CC);
++			if (j > start) {
++				j--;
++				while (j > start && !IS_SLASH(path[j])) {
++					j--;
++				}
++				if (!start) {
++					/* leading '..' must not be removed in case of relative path */
++					if (j == 0 && path[0] == '.' && path[1] == '.' &&
++					    IS_SLASH(path[2])) {
++						path[3] = '.';
++						path[4] = '.';
++						path[5] = DEFAULT_SLASH;
++						j = 5;
++					} else if (j > 0 && 
++				               path[j+1] == '.' && path[j+2] == '.' &&
++				               IS_SLASH(path[j+3])) {
++						j += 4;
++						path[j++] = '.';
++						path[j++] = '.';
++						path[j] = DEFAULT_SLASH;
++					}
++				}
++			} else if (!start && !j) {
++				/* leading '..' must not be removed in case of relative path */
++				path[0] = '.';
++				path[1] = '.';
++				path[2] = DEFAULT_SLASH;
++				j = 2;
++			}
++			return j;
++		}
++	
++		path[len] = 0;
++
++#ifdef PHP_WIN32
++		tmp = tsrm_do_alloca(len+1);
++		memcpy(tmp, path, len+1);
++#elif defined(NETWARE)
++
++		tmp = tsrm_do_alloca(len+1);
++		memcpy(tmp, path, len+1);
++#else
++		tmp = tsrm_do_alloca(len+1);
++		memcpy(tmp, path, len+1);
++
++		{
++#endif
++			if (i - 1 <= start) {
++				j = start;
++			} else {
++				/* some leading directories may be unaccessable */
++				j = php_zip_realpath_r(path, start, i-1, ll, t, use_realpath, 1, NULL TSRMLS_CC);
++				if (j > start) {
++					path[j++] = DEFAULT_SLASH;
++				}
++			}
++#ifdef PHP_WIN32
++			if (j < 0 || j + len - i >= MAXPATHLEN-1) {
++				tsrm_free_alloca(tmp);
++
++				return -1;
++			}
++			{
++				/* use the original file or directory name as it wasn't found */
++				memcpy(path+j, tmp+i, len-i+1);
++				j += (len-i);
++			}
++#else
++			if (j < 0 || j + len - i >= MAXPATHLEN-1) {
++				tsrm_free_alloca(tmp);
++				return -1;
++			}
++			memcpy(path+j, tmp+i, len-i+1);
++			j += (len-i);
++		}
++#endif
++
++		tsrm_free_alloca(tmp);
++		return j;
++	}
++}
++/* }}} */
++
++#define CWD_STATE_FREE(s)			\
++	free((s)->cwd);
++
++
++#define CWD_STATE_COPY(d, s)				\
++	(d)->cwd_length = (s)->cwd_length;		\
++	(d)->cwd = (char *) malloc((s)->cwd_length+1);	\
++	memcpy((d)->cwd, (s)->cwd, (s)->cwd_length+1);
++
++/* Resolve path relatively to state and put the real path into state */
++/* returns 0 for ok, 1 for error */
++int php_zip_virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath) /* {{{ */
++{
++	int path_length = strlen(path);
++	char resolved_path[MAXPATHLEN];
++	int start = 1;
++	int ll = 0;
++	time_t t;
++	int ret;
++	int add_slash;
++	TSRMLS_FETCH();
++
++	if (path_length == 0 || path_length >= MAXPATHLEN-1) {
++		return 1;
++	}
++
++	/* cwd_length can be 0 when getcwd() fails.
++	 * This can happen under solaris when a dir does not have read permissions
++	 * but *does* have execute permissions */
++	if (!IS_ABSOLUTE_PATH(path, path_length)) {
++		if (state->cwd_length == 0) {
++			/* resolve relative path */
++			start = 0;
++			memcpy(resolved_path , path, path_length + 1);
++		} else {
++			int state_cwd_length = state->cwd_length;
++
++#ifdef PHP_WIN32
++			if (IS_SLASH(path[0])) {
++				if (state->cwd[1] == ':') {
++					/* Copy only the drive name */
++					state_cwd_length = 2;
++				} else if (IS_UNC_PATH(state->cwd, state->cwd_length)) {
++					/* Copy only the share name */
++					state_cwd_length = 2;
++					while (IS_SLASH(state->cwd[state_cwd_length])) {
++						state_cwd_length++;
++					}						 
++					while (state->cwd[state_cwd_length] &&
++					       !IS_SLASH(state->cwd[state_cwd_length])) {
++						state_cwd_length++;
++					}						 
++					while (IS_SLASH(state->cwd[state_cwd_length])) {
++						state_cwd_length++;
++					}						 
++					while (state->cwd[state_cwd_length] &&
++					       !IS_SLASH(state->cwd[state_cwd_length])) {
++						state_cwd_length++;
++					}						 
++				}
++			}
++#endif
++			if (path_length + state_cwd_length + 1 >= MAXPATHLEN-1) {
++				return 1;
++			}
++			memcpy(resolved_path, state->cwd, state_cwd_length);
++			resolved_path[state_cwd_length] = DEFAULT_SLASH;
++			memcpy(resolved_path + state_cwd_length + 1, path, path_length + 1);
++			path_length += state_cwd_length + 1;
++		}
++	} else {		
++#ifdef PHP_WIN32
++		if (path_length > 2 && path[1] == ':' && !IS_SLASH(path[2])) {
++			resolved_path[0] = path[0];
++			resolved_path[1] = ':';
++			resolved_path[2] = DEFAULT_SLASH;
++			memcpy(resolved_path + 3, path + 2, path_length - 1);
++			path_length++;
++		} else
++#endif
++		memcpy(resolved_path, path, path_length + 1);
++	} 
++
++#ifdef PHP_WIN32
++	if (memchr(resolved_path, '*', path_length) ||
++	    memchr(resolved_path, '?', path_length)) {
++		return 1;
++	}
++#endif
++
++#ifdef PHP_WIN32
++	if (IS_UNC_PATH(resolved_path, path_length)) {
++		/* skip UNC name */
++		resolved_path[0] = DEFAULT_SLASH;
++		resolved_path[1] = DEFAULT_SLASH;
++		start = 2;
++		while (!IS_SLASH(resolved_path[start])) {
++			if (resolved_path[start] == 0) {
++				goto verify;
++			}
++			resolved_path[start] = toupper(resolved_path[start]);
++			start++;
++		}
++		resolved_path[start++] = DEFAULT_SLASH;
++		while (!IS_SLASH(resolved_path[start])) {
++			if (resolved_path[start] == 0) {
++				goto verify;
++			}
++			resolved_path[start] = toupper(resolved_path[start]);
++			start++;
++		}
++		resolved_path[start++] = DEFAULT_SLASH;
++	} else if (IS_ABSOLUTE_PATH(resolved_path, path_length)) {
++		/* skip DRIVE name */
++		resolved_path[0] = toupper(resolved_path[0]);
++		resolved_path[2] = DEFAULT_SLASH;
++		start = 3;
++	}
++#elif defined(NETWARE)
++	if (IS_ABSOLUTE_PATH(resolved_path, path_length)) {
++		/* skip VOLUME name */
++		start = 0;
++		while (start != ':') {
++			if (resolved_path[start] == 0) return -1;
++			start++;
++		}
++		start++;
++		if (!IS_SLASH(resolved_path[start])) return -1;
++		resolved_path[start++] = DEFAULT_SLASH;
++	}
++#endif
++
++	add_slash = (use_realpath != CWD_REALPATH) && path_length > 0 && IS_SLASH(resolved_path[path_length-1]);
++	t = CWDG(realpath_cache_ttl) ? 0 : -1;
++	path_length = php_zip_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0, NULL TSRMLS_CC);
++
++	if (path_length < 0) {
++		errno = ENOENT;
++		return 1;
++	}
++	
++	if (!start && !path_length) {
++		resolved_path[path_length++] = '.';
++	}
++	if (add_slash && path_length && !IS_SLASH(resolved_path[path_length-1])) {
++		if (path_length >= MAXPATHLEN-1) {
++			return -1;
++		}
++		resolved_path[path_length++] = DEFAULT_SLASH;
++	}
++	resolved_path[path_length] = 0;
++
++#ifdef PHP_WIN32
++verify:
++#endif
++	if (verify_path) {
++		cwd_state old_state;
++
++		CWD_STATE_COPY(&old_state, state);
++		state->cwd_length = path_length;
++		state->cwd = (char *) realloc(state->cwd, state->cwd_length+1);
++		memcpy(state->cwd, resolved_path, state->cwd_length+1);
++		if (verify_path(state)) {
++			CWD_STATE_FREE(state);
++			*state = old_state;
++			ret = 1;
++		} else {
++			CWD_STATE_FREE(&old_state);
++			ret = 0;
++		}
++	} else {
++		state->cwd_length = path_length;
++		state->cwd = (char *) realloc(state->cwd, state->cwd_length+1);
++		memcpy(state->cwd, resolved_path, state->cwd_length+1);
++		ret = 0;
++	}
++	return (ret);
++}
++/* }}} */
++
 +/* Flatten a path by creating a relative path (to .) */
 +static char * php_zip_make_relative_path(char *path, int path_len) /* {{{ */
 +{
@@ -47,7 +345,7 @@
  /* {{{ php_zip_extract_file */
  /* TODO: Simplify it */
  static int php_zip_extract_file(struct zip * za, char *dest, char *file, int file_len TSRMLS_DC)
-@@ -103,57 +143,78 @@ static int php_zip_extract_file(struct z
+@@ -103,57 +441,80 @@ static int php_zip_extract_file(struct z
  	char *file_basename;
  	size_t file_basename_len;
  	int is_dir_only = 0;
@@ -63,7 +361,9 @@
 +	/* Clean/normlize the path and then transform any path (absolute or relative)
 +		 to a path relative to cwd (../../mydir/foo.txt > mydir/foo.txt)
 +	 */
-+	virtual_file_ex(&new_state, file, NULL, CWD_EXPAND);
++	if (php_zip_virtual_file_ex(&new_state, file, NULL, CWD_EXPAND) == 1) {
++		return 0;
++	}
 +	path_cleaned =  php_zip_make_relative_path(new_state.cwd, new_state.cwd_length);
 +	path_cleaned_len = strlen(path_cleaned);
 +
@@ -140,7 +440,7 @@
  	}
  
  	/* check again the full path, not sure if it
-@@ -164,6 +225,7 @@ static int php_zip_extract_file(struct z
+@@ -164,6 +525,7 @@ static int php_zip_extract_file(struct z
  		efree(fullpath);
  		efree(file_dirname_fullpath);
  		efree(file_basename);
@@ -148,7 +448,7 @@
  		return 0;
  	}
  
-@@ -172,6 +234,7 @@ static int php_zip_extract_file(struct z
+@@ -172,6 +534,7 @@ static int php_zip_extract_file(struct z
  		efree(fullpath);
  		efree(file_dirname_fullpath);
  		efree(file_basename);
@@ -156,7 +456,7 @@
  		return 0;
  	}
  
-@@ -186,6 +249,7 @@ static int php_zip_extract_file(struct z
+@@ -186,6 +549,7 @@ static int php_zip_extract_file(struct z
  	efree(fullpath);
  	efree(file_basename);
  	efree(file_dirname_fullpath);
@@ -164,375 +464,3 @@
  
  	if (n<0) {
  		return 0;
---- php5-5.2.6.dfsg.1.orig/TSRM/tsrm_virtual_cwd.c
-+++ php5-5.2.6.dfsg.1/TSRM/tsrm_virtual_cwd.c
-@@ -654,24 +654,17 @@ static inline realpath_cache_bucket* rea
- CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath) /* {{{ */
- {
- 	int path_length = strlen(path);
--	cwd_state old_state;
--	char orig_path[MAXPATHLEN];
--	realpath_cache_bucket *bucket;
--	time_t t = 0;
-+	char resolved_path[MAXPATHLEN];
-+	int start = 1;
-+	int ll = 0;
-+	time_t t;
- 	int ret;
--	int use_cache;
--	int use_relative_path = 0;
--#ifdef TSRM_WIN32
--	int is_unc;
--#endif
-+	int add_slash;
- 	TSRMLS_FETCH();
- 
--	use_cache = ((use_realpath != CWD_EXPAND) && CWDG(realpath_cache_size_limit));
--
--	if (path_length == 0) 
--		return (1);
--	if (path_length >= MAXPATHLEN)
--		return (1);
-+	if (path_length == 0 || path_length >= MAXPATHLEN-1) {
-+		return 1;
-+	}
- 
- #if VIRTUAL_CWD_DEBUG
- 		fprintf(stderr,"cwd = %s path = %s\n", state->cwd, path);
-@@ -682,10 +675,10 @@ CWD_API int virtual_file_ex(cwd_state *s
- 	 * but *does* have execute permissions */
- 	if (!IS_ABSOLUTE_PATH(path, path_length)) {
- 		if (state->cwd_length == 0) {
--			use_cache = 0;
--			use_relative_path = 1;
-+			/* resolve relative path */
-+			start = 0;
-+			memcpy(resolved_path , path, path_length + 1);
- 		} else {
--			int orig_path_len;
- 			int state_cwd_length = state->cwd_length;
- 
- #ifdef TSRM_WIN32
-@@ -693,240 +686,109 @@ CWD_API int virtual_file_ex(cwd_state *s
- 				state_cwd_length = 2;
- 			}
- #endif
--			orig_path_len = path_length + state_cwd_length + 1;
--			if (orig_path_len >= MAXPATHLEN) {
-+			if (path_length + state_cwd_length + 1 >= MAXPATHLEN-1) {
- 				return 1;
- 			}
--			memcpy(orig_path, state->cwd, state_cwd_length);
--			orig_path[state_cwd_length] = DEFAULT_SLASH;
--			memcpy(orig_path + state_cwd_length + 1, path, path_length + 1);
--			path = orig_path;
--			path_length = orig_path_len; 
-+			memcpy(resolved_path, state->cwd, state_cwd_length);
-+			resolved_path[state_cwd_length] = DEFAULT_SLASH;
-+			memcpy(resolved_path + state_cwd_length + 1, path, path_length + 1);
-+			path_length += state_cwd_length + 1;
- 		}
--	}
-+	} else {		
-+		memcpy(resolved_path , path, path_length + 1);
-+	} 
- 
--	if (use_cache) {
--		t = CWDG(realpath_cache_ttl)?time(0):0;
--		if ((bucket = realpath_cache_find(path, path_length, t TSRMLS_CC)) != NULL) {		
--			int len = bucket->realpath_len;
--
--			CWD_STATE_COPY(&old_state, state);
--			state->cwd = (char *) realloc(state->cwd, len+1);
--			memcpy(state->cwd, bucket->realpath, len+1);
--			state->cwd_length = len;
--			if (verify_path && verify_path(state)) {
--				CWD_STATE_FREE(state);
--				*state = old_state;
--				return 1;
--			} else {
--				CWD_STATE_FREE(&old_state);
--				return 0;
--			}
--		}
-+#ifdef TSRM_WIN32
-+	if (memchr(resolved_path, '*', path_length) ||
-+	    memchr(resolved_path, '?', path_length)) {
-+		return 1;
- 	}
--
--	if (use_realpath != CWD_EXPAND) {
--#if !defined(TSRM_WIN32) && !defined(NETWARE)
--		char resolved_path[MAXPATHLEN];
--
--		if (!realpath(path, resolved_path)) {  /* Note: Not threadsafe on older *BSD's */
--			if (use_realpath == CWD_REALPATH) {
--				return 1;
--			}
--			goto no_realpath;
--		}
--		use_realpath = CWD_REALPATH;
--		CWD_STATE_COPY(&old_state, state);
--
--		state->cwd_length = strlen(resolved_path);
--		state->cwd = (char *) realloc(state->cwd, state->cwd_length+1);
--		memcpy(state->cwd, resolved_path, state->cwd_length+1);
--#else
--		goto no_realpath;
- #endif
--	} else {
--		char *ptr, *path_copy, *free_path;
--		char *tok;
--		int ptr_length;
--no_realpath:
- 
- #ifdef TSRM_WIN32
--		if (memchr(path, '*', path_length) ||
--		    memchr(path, '?', path_length)) {
--			return 1;
-+	if (IS_UNC_PATH(resolved_path, path_length)) {
-+		/* skip UNC name */
-+		resolved_path[0] = DEFAULT_SLASH;
-+		resolved_path[1] = DEFAULT_SLASH;
-+		start = 2;
-+		while (!IS_SLASH(resolved_path[start])) {
-+			if (resolved_path[start] == 0) {
-+				goto verify;
-+			}
-+			resolved_path[start] = toupper(resolved_path[start]);
-+			start++;
- 		}
--#endif
--
--		free_path = path_copy = tsrm_strndup(path, path_length);
--		CWD_STATE_COPY(&old_state, state);
--
--#ifdef TSRM_WIN32
--		ret = 0;
--		is_unc = 0;
--		if (path_length >= 2 && path[1] == ':') {			
--			state->cwd = (char *) realloc(state->cwd, 2 + 1);
--			state->cwd[0] = toupper(path[0]);
--			state->cwd[1] = ':';
--			state->cwd[2] = '\0';
--			state->cwd_length = 2;
--			path_copy += 2;
--		} else if (IS_UNC_PATH(path, path_length)) {
--			state->cwd = (char *) realloc(state->cwd, 1 + 1);
--			state->cwd[0] = DEFAULT_SLASH;
--			state->cwd[1] = '\0';
--			state->cwd_length = 1;
--			path_copy += 2;
--			is_unc = 2;
--		} else {
--#endif
--			state->cwd = (char *) realloc(state->cwd, 1);
--			state->cwd[0] = '\0';
--			state->cwd_length = 0;
--#ifdef TSRM_WIN32
-+		resolved_path[start++] = DEFAULT_SLASH;
-+		while (!IS_SLASH(resolved_path[start])) {
-+			if (resolved_path[start] == 0) {
-+				goto verify;
-+			}
-+			resolved_path[start] = toupper(resolved_path[start]);
-+			start++;
- 		}
--#endif
--		
--		tok = NULL;
--		ptr = tsrm_strtok_r(path_copy, TOKENIZER_STRING, &tok);
--		while (ptr) {
--			ptr_length = strlen(ptr);
--
--			if (IS_DIRECTORY_UP(ptr, ptr_length)) {
--				char save;
--
--				if (use_relative_path) {
--					CWD_STATE_FREE(state);
--					*state = old_state;
--					return 1;
--				}
--
--				save = DEFAULT_SLASH;
--
--#define PREVIOUS state->cwd[state->cwd_length - 1]
--
--				while (IS_ABSOLUTE_PATH(state->cwd, state->cwd_length) &&
--						!IS_SLASH(PREVIOUS)) {
--					save = PREVIOUS;
--					PREVIOUS = '\0';
--					state->cwd_length--;
--				}
--
--				if (!IS_ABSOLUTE_PATH(state->cwd, state->cwd_length)) {
--					state->cwd[state->cwd_length++] = save;
--					state->cwd[state->cwd_length] = '\0';
--				} else {
--					PREVIOUS = '\0';
--					state->cwd_length--;
--				}
--			} else if (!IS_DIRECTORY_CURRENT(ptr, ptr_length)) {
--				if (use_relative_path) {
--					state->cwd = (char *) realloc(state->cwd, state->cwd_length+ptr_length+1);
--					use_relative_path = 0;
--				} else {
--					state->cwd = (char *) realloc(state->cwd, state->cwd_length+ptr_length+1+1);
--#ifdef TSRM_WIN32
--					/* Windows 9x will consider C:\\Foo as a network path. Avoid it. */
--					if (state->cwd_length < 2 ||
--					    (state->cwd[state->cwd_length-1]!='\\' && state->cwd[state->cwd_length-1]!='/') ||
--							IsDBCSLeadByte(state->cwd[state->cwd_length-2])) {
--						state->cwd[state->cwd_length++] = DEFAULT_SLASH;
--					}
-+		resolved_path[start++] = DEFAULT_SLASH;
-+	} else if (IS_ABSOLUTE_PATH(resolved_path, path_length)) {
-+		/* skip DRIVE name */
-+		resolved_path[0] = toupper(resolved_path[0]);
-+		resolved_path[2] = DEFAULT_SLASH;
-+		start = 3;
-+	}
- #elif defined(NETWARE)
--					/* 
--					Below code keeps appending to state->cwd a File system seperator
--					cases where this appending should not happen is given below,
--					a) sys: should just be left as it is
--					b) sys:system should just be left as it is,
--						Colon is allowed only in the first token as volume names alone can have the : in their names.
--						Files and Directories cannot have : in their names
--						So the check goes like this,
--						For second token and above simply append the DEFAULT_SLASH to the state->cwd.
--						For first token check for the existence of : 
--						if it exists don't append the DEFAULT_SLASH to the state->cwd.
--					*/
--					if(((state->cwd_length == 0) && (strchr(ptr, ':') == NULL)) || (state->cwd_length > 0)) {
--						state->cwd[state->cwd_length++] = DEFAULT_SLASH;
--					}
--#else
--					state->cwd[state->cwd_length++] = DEFAULT_SLASH;
--#endif
--				}
--				memcpy(&state->cwd[state->cwd_length], ptr, ptr_length+1);
--
--#ifdef TSRM_WIN32
--				if (use_realpath != CWD_EXPAND) {
--					WIN32_FIND_DATA data;
--					HANDLE hFind;
--
--					if ((hFind = FindFirstFile(state->cwd, &data)) != INVALID_HANDLE_VALUE) {
--						int length = strlen(data.cFileName);
--
--						if (length != ptr_length) {
--							state->cwd = (char *) realloc(state->cwd, state->cwd_length+length+1);
--						}
--						memcpy(&state->cwd[state->cwd_length], data.cFileName, length+1);
--						ptr_length = length;
--						FindClose(hFind);
--						ret = 0;
--					} else if (use_realpath == CWD_REALPATH) {
--						if (is_unc) {
--							/* skip share name */
--							is_unc--;
--							ret = 0;
--						} else {
--							ret = 1;
--						}
--					}
--				}
--#endif
--
--				state->cwd_length += ptr_length;
--			}
--			ptr = tsrm_strtok_r(NULL, TOKENIZER_STRING, &tok);
-+	if (IS_ABSOLUTE_PATH(resolved_path, path_length)) {
-+		/* skip VOLUME name */
-+		start = 0;
-+		while (start != ':') {
-+			if (resolved_path[start] == 0) return -1;
-+			start++;
- 		}
--		free(free_path);
-+		start++;
-+		if (!IS_SLASH(resolved_path[start])) return -1;
-+		resolved_path[start++] = DEFAULT_SLASH;
-+	}
-+#endif
- 
--		if (use_realpath == CWD_REALPATH) {
--			if (ret) {
--				CWD_STATE_FREE(state);
--				*state = old_state;					
--				return 1;
--			}
--		} else {
--#if defined(TSRM_WIN32) || defined(NETWARE)
--			if (path[path_length-1] == '\\' || path[path_length-1] == '/') {
--#else 
--			if (path[path_length-1] == '/') {
--#endif
--				state->cwd = (char*)realloc(state->cwd, state->cwd_length + 2);
--				state->cwd[state->cwd_length++] = DEFAULT_SLASH;
--				state->cwd[state->cwd_length] = 0;
--			}
--		}
- 
--		if (state->cwd_length == COPY_WHEN_ABSOLUTE(state->cwd)) {
--			state->cwd = (char *) realloc(state->cwd, state->cwd_length+1+1);
--			state->cwd[state->cwd_length] = DEFAULT_SLASH;
--			state->cwd[state->cwd_length+1] = '\0';
--			state->cwd_length++;
-+	add_slash = (use_realpath != CWD_REALPATH) && path_length > 0 && IS_SLASH(resolved_path[path_length-1]);	
-+	t = CWDG(realpath_cache_ttl) ? 0 : -1;
-+	path_length = tsrm_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0 TSRMLS_CC);
-+	
-+	if (path_length < 0) {
-+		return 1;
-+	}
-+	
-+	if (!start && !path_length) {
-+		resolved_path[path_length++] = '.';
-+	}
-+	if (add_slash && path_length && !IS_SLASH(resolved_path[path_length-1])) {
-+		if (path_length >= MAXPATHLEN-1) {
-+			return -1;
- 		}
-+		resolved_path[path_length++] = DEFAULT_SLASH;
- 	}
-+	resolved_path[path_length] = 0;
- 
--	/* Store existent file in realpath cache. */
- #ifdef TSRM_WIN32
--	if (use_cache && !is_unc) {
--#else
--	if (use_cache && (use_realpath == CWD_REALPATH)) {
-+verify:
- #endif
--		realpath_cache_add(path, path_length, state->cwd, state->cwd_length, t TSRMLS_CC);
--	}
-+	if (verify_path) {
-+		cwd_state old_state;
- 
--	if (verify_path && verify_path(state)) {
--		CWD_STATE_FREE(state);
--		*state = old_state;
--		ret = 1;
-+		CWD_STATE_COPY(&old_state, state);
-+		state->cwd_length = path_length;
-+		state->cwd = (char *) realloc(state->cwd, state->cwd_length+1);
-+		memcpy(state->cwd, resolved_path, state->cwd_length+1);
-+		if (verify_path(state)) {
-+			CWD_STATE_FREE(state);
-+			*state = old_state;
-+			ret = 1;
-+		} else {
-+			CWD_STATE_FREE(&old_state);
-+			ret = 0;
-+		}
- 	} else {
--		CWD_STATE_FREE(&old_state);
-+		state->cwd_length = path_length;
-+		state->cwd = (char *) realloc(state->cwd, state->cwd_length+1);
-+		memcpy(state->cwd, resolved_path, state->cwd_length+1);
- 		ret = 0;
- 	}
- 	




More information about the Pkg-php-commits mailing list