aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/testing/selftests/nolibc
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2023-08-03 09:28:56 +0200
committerWilly Tarreau <w@1wt.eu>2023-08-23 05:17:07 +0200
commit9c5e490093e83e165022e0311bd7df5aa06cc860 (patch)
tree91fea461e88eec1e8eb94c6a58cebfe70e84697e /tools/testing/selftests/nolibc
parentselftests/nolibc: use correct return type for read() and write() (diff)
downloadwireguard-linux-9c5e490093e83e165022e0311bd7df5aa06cc860.tar.xz
wireguard-linux-9c5e490093e83e165022e0311bd7df5aa06cc860.zip
selftests/nolibc: prevent out of bounds access in expect_vfprintf
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>
Diffstat (limited to 'tools/testing/selftests/nolibc')
-rw-r--r--tools/testing/selftests/nolibc/nolibc-test.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 23a5e4c57083..e2b70641a1e7 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -1051,7 +1051,6 @@ static int expect_vfprintf(int llen, int c, const char *expected, const char *fm
lseek(fd, 0, SEEK_SET);
r = read(fd, buf, sizeof(buf) - 1);
- buf[r] = '\0';
fclose(memfile);
@@ -1061,6 +1060,7 @@ static int expect_vfprintf(int llen, int c, const char *expected, const char *fm
return 1;
}
+ buf[r] = '\0';
llen += printf(" \"%s\" = \"%s\"", expected, buf);
ret = strncmp(expected, buf, c);