Merge pull request #5316 from genosse-einhorn/master

VHD: fix buffer overflow in calc_relative_path
This commit is contained in:
Jonathan Campbell 2024-12-15 08:52:41 -08:00 committed by GitHub
commit 38151d33be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -89,15 +89,16 @@ char* calc_relative_path(const char* base, const char* child) {
x++;
}
// allocates space for the resulting string and premits any needed ".\" or "..\"
y = (char*)malloc(strlen(q) + n * 3 + 2); // n * strlen("..\\")
z = y;
if (!n) {
if (n == 0) {
z = y = (char *)malloc(strlen(p) + 2 + 1);
strcpy(z, ".\\");
z += 2;
}
while(n--) {
strcpy(z, "..\\");
z += 3;
} else {
z = y = (char*)malloc(strlen(p) + n * 3 + 1); // n * strlen("..\\")
while(n--) {
strcpy(z, "..\\");
z += 3;
}
}
// finally adds base relative pathname
strcpy(z, p);