Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Sep 2021 03:11:36 +0000
From:      bugzilla-noreply@freebsd.org
To:        testing@FreeBSD.org
Subject:   [Bug 258701] tests: lib/libutil/pidfile_test flaky due to uninitialized array
Message-ID:  <bug-258701-32464-VBhUTw93P1@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-258701-32464@https.bugs.freebsd.org/bugzilla/>
References:  <bug-258701-32464@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D258701

--- Comment #1 from Konstantin Belousov <kib@FreeBSD.org> ---
Wouldn't it be better to guarantee null-termination of the read string?

diff --git a/lib/libutil/tests/pidfile_test.c
b/lib/libutil/tests/pidfile_test.c
index 9e516c35273c..9bfa6754ce54 100644
--- a/lib/libutil/tests/pidfile_test.c
+++ b/lib/libutil/tests/pidfile_test.c
@@ -286,7 +286,8 @@ test_pidfile_relative(void)
        fd =3D open(path, O_RDONLY);
        if (fd < 0)
                return (strerror(errno));
-       if (read(fd, pid, sizeof(pid)) < 0)
+       memset(pid, 0, sizeof(pid));
+       if (read(fd, pid, sizeof(pid) - 1) < 0)
                return (strerror(errno));
        if (atoi(pid) !=3D getpid())
                return ("pid mismatch");

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-258701-32464-VBhUTw93P1>