blob: 57970824f6ebb18b90c23cd27613b3026fdd1f73 [file] [log] [blame]
Andrew Geissler82c905d2020-04-13 13:39:40 -05001From cd7091a7d88306004ca98c5dafcc40f44589b105 Mon Sep 17 00:00:00 2001
2From: Jens Rehsack <sno@netbsd.org>
3Date: Mon, 24 Feb 2020 10:52:21 +0100
4Subject: [PATCH 1/3] src/dir.c: fix buffer-overflow warning
5
6Fix compiler warning:
7 src/dir.c:1294:7: warning: 'strncpy' specified bound depends on the
8 length of the source argument [-Wstringop-overflow=]
9
10The existing code assumes `path` will never exceed `MAXPATHLEN`. Also the
11size of the buffer is increased by 1 to hold a path with the length of
12`MAXPATHLEN` and trailing `0`.
13
14Signed-off-by: Jens Rehsack <sno@netbsd.org>
15---
16Upstream-Status: Pending (https://savannah.gnu.org/bugs/?57888)
17
18 src/dir.c | 6 +++---
19 1 file changed, 3 insertions(+), 3 deletions(-)
20
21diff --git a/src/dir.c b/src/dir.c
22index 862a18e..cad4c4a 100644
23--- a/src/dir.c
24+++ b/src/dir.c
25@@ -1289,10 +1289,10 @@ local_stat (const char *path, struct stat *buf)
26 if (plen > 1 && path[plen - 1] == '.'
27 && (path[plen - 2] == '/' || path[plen - 2] == '\\'))
28 {
29- char parent[MAXPATHLEN];
30+ char parent[MAXPATHLEN+1];
31
32- strncpy (parent, path, plen - 2);
33- parent[plen - 2] = '\0';
34+ strncpy (parent, path, MAXPATHLEN);
35+ parent[MIN(plen - 2, MAXPATHLEN)] = '\0';
36 if (stat (parent, buf) < 0 || !_S_ISDIR (buf->st_mode))
37 return -1;
38 }
39--
402.17.1
41