summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2023-07-26 08:08:13 +0200
committerWilly Tarreau <w@1wt.eu>2023-08-23 05:17:07 +0200
commit447e56023fc281c588e4977add552f4d49d78b22 (patch)
tree2f20d212ca59452e609c464b3484dcc00be4f296
parent4893c22eb2f4364bc037e9451dfc3bd36a231901 (diff)
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 <linux@weissschuh.net> Signed-off-by: Willy Tarreau <w@1wt.eu>
-rw-r--r--tools/testing/selftests/nolibc/nolibc-test.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 737205702e3d..3f5a256631ca 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);
}