Skip to content

Commit

Permalink
selftests/nolibc: prevent out of bounds access in expect_vfprintf
Browse files Browse the repository at this point in the history
[ Upstream commit 9c5e490 ]

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>
  • Loading branch information
t-8ch authored and gregkh committed Sep 23, 2023
1 parent 21c634e commit 886c7f9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/testing/selftests/nolibc/nolibc-test.c
Expand Up @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit 886c7f9

Please sign in to comment.