From ac20fa249f129b5c1eb65d378baf4f954dd03bc9 Mon Sep 17 00:00:00 2001 From: Eric van Gyzen Date: Fri, 23 Jul 2021 08:49:55 -0500 Subject: [PATCH] aio_md_test: NUL-terminate result of readlink readlink does not NUL-terminate the output buffer. This led to spurious failures to destroy the md device because the unit number was garbage. NUL-terminate the output buffer. Reported by: ASLR MFC after: 1 week Sponsored by: Dell EMC Isilon (cherry picked from commit ea0e1b19f232331bffa75a0a64a6859c40f1cc4d) --- tests/sys/aio/aio_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/sys/aio/aio_test.c b/tests/sys/aio/aio_test.c index af2e3823d1ff..0f929c510e9f 100644 --- a/tests/sys/aio/aio_test.c +++ b/tests/sys/aio/aio_test.c @@ -767,8 +767,9 @@ aio_md_cleanup(void) strerror(errno)); return; } - n = readlink(MDUNIT_LINK, buf, sizeof(buf)); + n = readlink(MDUNIT_LINK, buf, sizeof(buf) - 1); if (n > 0) { + buf[n] = '\0'; if (sscanf(buf, "%d", &unit) == 1 && unit >= 0) { bzero(&mdio, sizeof(mdio)); mdio.md_version = MDIOVERSION;