Commit 9c5e4900 authored by Thomas Weißschuh's avatar Thomas Weißschuh Committed by Willy Tarreau
Browse files

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: default avatarThomas Weißschuh <linux@weissschuh.net>
Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
parent 37266a9e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);