lib/misc: Fix out-of-bounds reads in get_absolute_path backward scans

This commit is contained in:
Mintsuki
2026-04-14 02:24:26 +02:00
parent 0556f4bfb4
commit 851352d7d1

View File

@@ -90,12 +90,12 @@ first_run:
}
if ((!strncmp(path, "..\0", 3))
|| (!strncmp(path, "../\0", 4))) {
while (*path_ptr != '/') path_ptr--;
while (path_ptr > orig_ptr && *path_ptr != '/') path_ptr--;
if (path_ptr == orig_ptr) path_ptr++;
goto term;
}
if (!strncmp(path, "../", 3)) {
while (*path_ptr != '/') path_ptr--;
while (path_ptr > orig_ptr && *path_ptr != '/') path_ptr--;
if (path_ptr == orig_ptr) path_ptr++;
path += 2;
*path_ptr = 0;
@@ -105,7 +105,7 @@ first_run:
path += 1;
continue;
}
if (((path_ptr - 1) != orig_ptr) && (*(path_ptr - 1) != '/')) {
if (path_ptr > orig_ptr && ((path_ptr - 1) != orig_ptr) && (*(path_ptr - 1) != '/')) {
if (path_ptr >= end_ptr) return false;
*path_ptr = '/';
path_ptr++;
@@ -113,7 +113,7 @@ first_run:
continue;
case '\0':
term:
if ((*(path_ptr - 1) == '/') && ((path_ptr - 1) != orig_ptr))
if (path_ptr > orig_ptr && (*(path_ptr - 1) == '/') && ((path_ptr - 1) != orig_ptr))
path_ptr--;
*path_ptr = 0;
return true;