From: Thomas Weißschuh Date: Wed, 26 Jul 2023 06:08:13 +0000 (+0200) Subject: selftests/nolibc: avoid buffer underrun in space printing X-Git-Tag: v6.6.7~2092^2~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=447e56023fc281c588e4977add552f4d49d78b22;p=platform%2Fkernel%2Flinux-starfive.git selftests/nolibc: avoid buffer underrun in space printing If the test description is longer than the status alignment the parameter 'n' to putcharn() would lead to a signed underflow that then gets converted to a very large unsigned value. This in turn leads out-of-bound writes in memset() crashing the application. The failure case of EXPECT_PTRER() used in "mmap_bad" exhibits this exact behavior. Fixes: 29f5540be392 ("selftests/nolibc: add EXPECT_PTREQ, EXPECT_PTRNE and EXPECT_PTRER") Signed-off-by: Thomas Weißschuh Signed-off-by: Willy Tarreau --- diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 7372057..3f5a256 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -151,7 +151,8 @@ static void result(int llen, enum RESULT r) else msg = "[FAIL]"; - putcharn(' ', 64 - llen); + if (llen < 64) + putcharn(' ', 64 - llen); puts(msg); }