mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-15 15:15:47 +00:00
selftests/nolibc: prevent out of bounds access in expect_vfprintf
[ Upstream commit 9c5e490093
]
If read() fails and returns -1 (or returns garbage for some other
reason) buf would be accessed out of bounds.
Only use the return value of read() after it has been validated.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
21c634eb69
commit
886c7f95e7
1 changed files with 1 additions and 1 deletions
|
@ -769,7 +769,6 @@ static int expect_vfprintf(int llen, size_t c, const char *expected, const char
|
|||
lseek(fd, 0, SEEK_SET);
|
||||
|
||||
r = read(fd, buf, sizeof(buf) - 1);
|
||||
buf[r] = '\0';
|
||||
|
||||
fclose(memfile);
|
||||
|
||||
|
@ -779,6 +778,7 @@ static int expect_vfprintf(int llen, size_t c, const char *expected, const char
|
|||
return 1;
|
||||
}
|
||||
|
||||
buf[r] = '\0';
|
||||
llen += printf(" \"%s\" = \"%s\"", expected, buf);
|
||||
ret = strncmp(expected, buf, c);
|
||||
|
||||
|
|
Loading…
Reference in a new issue