]> git.ipfire.org Git - thirdparty/make.git/commitdiff
* src/dir.c (local_stat): [WINDOWS32] Fix buffer-overflow warning.
authorJens Rehsack <sno@netbsd.org>
Mon, 24 Feb 2020 09:52:21 +0000 (10:52 +0100)
committerPaul Smith <psmith@gnu.org>
Tue, 31 Mar 2020 04:48:57 +0000 (00:48 -0400)
[SV 57888] Provide space for the path to use MAXPATHLEN plus nul.

Signed-off-by: Jens Rehsack <sno@netbsd.org>
Copyright-paperwork-exempt: yes

src/dir.c

index 862a18ead91399d8107eb7e72a7c76e17589b487..2b2abf33195d6532d9a5abf38257926b7e0d544b 100644 (file)
--- a/src/dir.c
+++ b/src/dir.c
@@ -1286,13 +1286,13 @@ local_stat (const char *path, struct stat *buf)
   /* Make sure the parent of "." exists and is a directory, not a
      file.  This is because 'stat' on Windows normalizes the argument
      foo/. => foo without checking first that foo is a directory.  */
-  if (plen > 1 && path[plen - 1] == '.'
+  if (plen > 2 && 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;
     }