fix for buffer overrun with making a path relative.

would only happen when the names of the path and the relative location matched which isnt likely but happened today when Soenke somehow made a file link to its self.
This commit is contained in:
Campbell Barton
2010-06-03 13:05:45 +00:00
parent 4385add665
commit 566c92fff7

View File

@@ -354,8 +354,6 @@ void BLI_cleanup_file(const char *relabase, char *dir)
void BLI_path_rel(char *file, const char *relfile)
{
char * p;
char * q;
char * lslash;
char temp[FILE_MAXDIR+FILE_MAXFILE];
char res[FILE_MAXDIR+FILE_MAXFILE];
@@ -403,11 +401,18 @@ void BLI_path_rel(char *file, const char *relfile)
{
/* find the prefix of the filename that is equal for both filenames.
This is replaced by the two slashes at the beginning */
p = temp;
q = file;
while (*p == *q) {
char *p= temp;
char *q= file;
while ((*p == *q)) {
++p; ++q;
/* dont search beyond the end of the string
* in the rare case they match */
if ((*p=='\0') || (*q=='\0')) {
break;
}
}
/* we might have passed the slash when the beginning of a dir matches
so we rewind. Only check on the actual filename
*/