fix for out of bounds read in BLI_path_rel

This commit is contained in:
Campbell Barton 2013-06-27 20:47:59 +00:00
parent d1f4827a40
commit eba9b4f6c1

@ -530,6 +530,7 @@ void BLI_path_rel(char *file, const char *relfile)
* This is replaced by the two slashes at the beginning */
char *p = temp;
char *q = file;
char *r = res;
#ifdef WIN32
while (tolower(*p) == tolower(*q))
@ -557,20 +558,23 @@ void BLI_path_rel(char *file, const char *relfile)
while ( (p >= temp) && (*p != '/') ) { --p; --q; }
}
strcpy(res, "//");
r += BLI_strcpy_rlen(r, "//");
/* p now points to the slash that is at the beginning of the part
* where the path is different from the relative path.
* We count the number of directories we need to go up in the
* hierarchy to arrive at the common 'prefix' of the path
*/
if (p < temp) p = temp;
while (p && p < lslash) {
if (*p == '/')
strcat(res, "../");
if (*p == '/') {
r += BLI_strcpy_rlen(r, "../");
}
p++;
}
strcat(res, q + 1); /* don't copy the slash at the beginning */
/* don't copy the slash at the beginning */
r += BLI_strcpy_rlen(r, q + 1);
#ifdef WIN32
BLI_char_switch(res + 2, '/', '\\');