From b7caec3e4cab2b1f16743c1df3e48d78a4daa4aa Mon Sep 17 00:00:00 2001 From: Ngie Cooper Date: Sat, 10 Dec 2016 16:15:18 -0800 Subject: [PATCH] Increase the size of buff by 1 and adjust the readlink(2) call to subtract the buffer len by 1 to account for the needed space for a NUL terminator, as readlink isn't guaranteed to provide one Reported by: Coverity CID: 1331293, 1332105 --- tar/test/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tar/test/main.c b/tar/test/main.c index 71a0c49e5..6077af5f0 100644 --- a/tar/test/main.c +++ b/tar/test/main.c @@ -1590,7 +1590,7 @@ is_symlink(const char *file, int line, * really not much point in bothering with this. */ return (0); #else - char buff[300]; + char buff[301]; struct stat st; ssize_t linklen; int r; @@ -1607,7 +1607,7 @@ is_symlink(const char *file, int line, return (0); if (contents == NULL) return (1); - linklen = readlink(pathname, buff, sizeof(buff)); + linklen = readlink(pathname, buff, sizeof(buff) - 1); if (linklen < 0) { failure_start(file, line, "Can't read symlink %s", pathname); failure_finish(NULL); -- 2.47.2