From cd7091a7d88306004ca98c5dafcc40f44589b105 Mon Sep 17 00:00:00 2001 From: Jens Rehsack Date: Mon, 24 Feb 2020 10:52:21 +0100 Subject: [PATCH 1/3] src/dir.c: fix buffer-overflow warning Fix compiler warning: src/dir.c:1294:7: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=] The existing code assumes `path` will never exceed `MAXPATHLEN`. Also the size of the buffer is increased by 1 to hold a path with the length of `MAXPATHLEN` and trailing `0`. Signed-off-by: Jens Rehsack --- Upstream-Status: Pending (https://savannah.gnu.org/bugs/?57888) src/dir.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dir.c b/src/dir.c index 862a18e..cad4c4a 100644 --- a/src/dir.c +++ b/src/dir.c @@ -1289,10 +1289,10 @@ local_stat (const char *path, struct stat *buf) if (plen > 1 && path[plen - 1] == '.' && (path[plen - 2] == '/' || path[plen - 2] == '\\')) { - char parent[MAXPATHLEN]; + char parent[MAXPATHLEN+1]; - strncpy (parent, path, plen - 2); - parent[plen - 2] = '\0'; + strncpy (parent, path, MAXPATHLEN); + parent[MIN(plen - 2, MAXPATHLEN)] = '\0'; if (stat (parent, buf) < 0 || !_S_ISDIR (buf->st_mode)) return -1; } -- 2.17.1