[Bug 258701] tests: lib/libutil/pidfile_test flaky due to uninitialized array

From: <bugzilla-noreply_at_freebsd.org>
Date: Fri, 24 Sep 2021 03:11:36 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=258701

--- 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 = 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) != getpid())
                return ("pid mismatch");

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