pidfile test: guarantee nul termination of the read pid string

PR:	258701
Based on the submission by:	sigsys@gmail.com
MFC after:	1 week
This commit is contained in:
Konstantin Belousov 2021-09-24 06:12:20 +03:00
parent d7cf1b262f
commit 364790beaf

View File

@ -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");