From 364790beafec707ca3e334683e4030684d829be2 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Fri, 24 Sep 2021 06:12:20 +0300 Subject: [PATCH] pidfile test: guarantee nul termination of the read pid string PR: 258701 Based on the submission by: sigsys@gmail.com MFC after: 1 week --- lib/libutil/tests/pidfile_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/libutil/tests/pidfile_test.c b/lib/libutil/tests/pidfile_test.c index 9e516c35273..9bfa6754ce5 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");