Skip to content

Commit d6966f1

Browse files
committed
lib/misc: Fix out-of-bounds reads in get_absolute_path backward scans
1 parent b2eade6 commit d6966f1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

common/lib/misc.s2.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ bool get_absolute_path(char *path_ptr, const char *path, const char *pwd, size_t
9090
}
9191
if ((!strncmp(path, "..\0", 3))
9292
|| (!strncmp(path, "../\0", 4))) {
93-
while (*path_ptr != '/') path_ptr--;
93+
while (path_ptr > orig_ptr && *path_ptr != '/') path_ptr--;
9494
if (path_ptr == orig_ptr) path_ptr++;
9595
goto term;
9696
}
9797
if (!strncmp(path, "../", 3)) {
98-
while (*path_ptr != '/') path_ptr--;
98+
while (path_ptr > orig_ptr && *path_ptr != '/') path_ptr--;
9999
if (path_ptr == orig_ptr) path_ptr++;
100100
path += 2;
101101
*path_ptr = 0;
@@ -105,15 +105,15 @@ bool get_absolute_path(char *path_ptr, const char *path, const char *pwd, size_t
105105
path += 1;
106106
continue;
107107
}
108-
if (((path_ptr - 1) != orig_ptr) && (*(path_ptr - 1) != '/')) {
108+
if (path_ptr > orig_ptr && ((path_ptr - 1) != orig_ptr) && (*(path_ptr - 1) != '/')) {
109109
if (path_ptr >= end_ptr) return false;
110110
*path_ptr = '/';
111111
path_ptr++;
112112
}
113113
continue;
114114
case '\0':
115115
term:
116-
if ((*(path_ptr - 1) == '/') && ((path_ptr - 1) != orig_ptr))
116+
if (path_ptr > orig_ptr && (*(path_ptr - 1) == '/') && ((path_ptr - 1) != orig_ptr))
117117
path_ptr--;
118118
*path_ptr = 0;
119119
return true;

0 commit comments

Comments
 (0)