]> xenbits.xensource.com Git - people/royger/freebsd.git/commitdiff
aio_md_test: NUL-terminate result of readlink
authorEric van Gyzen <vangyzen@FreeBSD.org>
Fri, 23 Jul 2021 13:49:55 +0000 (08:49 -0500)
committerEric van Gyzen <vangyzen@FreeBSD.org>
Wed, 2 Mar 2022 21:56:30 +0000 (15:56 -0600)
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

index af2e3823d1ff38f129f1e8b7fd5bcd5f831e4d83..0f929c510e9f3d1813751af97e0f2fa4475fbc6f 100644 (file)
@@ -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;