[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 +0000
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=258701

--- Comment #1 from Konstantin Belousov <kib_at_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
_at__at_ -286,7 +286,8 _at__at_ 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.
Received on Fri Sep 24 2021 - 03:11:36 UTC

Original text of this message