summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/make/make/0001-src-dir.c-fix-buffer-overflow-warning.patch
blob: 57970824f6ebb18b90c23cd27613b3026fdd1f73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
From cd7091a7d88306004ca98c5dafcc40f44589b105 Mon Sep 17 00:00:00 2001
From: Jens Rehsack <sno@netbsd.org>
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 <sno@netbsd.org>
---
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