Skip to content

Commit d236920

Browse files
AntonMoryakovlucasdemarchi
authored andcommitted
shared: util.c: fix buffer overflow in alias_normalize()
The while-loop inside the '[' case of alias_normalize() increments the index 'i' without checking against PATH_MAX bounds. If the input string contains an opening '[' followed by many characters without a closing ']', the index can exceed PATH_MAX-1, causing a buffer overflow when writing to buf[i]. Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Link: #431 Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
1 parent 2ef7ade commit d236920

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

shared/util.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ int alias_normalize(const char *alias, char buf[static PATH_MAX], size_t *len)
7979
case ']':
8080
return -EINVAL;
8181
case '[':
82-
while (alias[i] != ']' && alias[i] != '\0') {
82+
while (i < PATH_MAX - 1 && alias[i] != ']' && alias[i] != '\0') {
8383
buf[i] = alias[i];
8484
i++;
8585
}
86+
if (i >= PATH_MAX - 1)
87+
return -EINVAL;
8688

8789
if (alias[i] != ']')
8890
return -EINVAL;

0 commit comments

Comments
 (0)