]> Savannah Git Hosting - gnulib.git/commitdiff
canonicalize-lgpl: Support the case path_max > INT_MAX.
authorBruno Haible <bruno@clisp.org>
Fri, 14 Oct 2016 00:49:05 +0000 (02:49 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 15 Oct 2016 12:51:09 +0000 (14:51 +0200)
* lib/canonicalize-lgpl.c (__realpath): Declare n as ssize_t, not int.

ChangeLog
lib/canonicalize-lgpl.c

index 5b5f81dc781eb96bd4cb6148294509fe1933a741..4d84310299423133ca093bfb3070f238453fbe16 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2016-10-14  Bruno Haible  <bruno@clisp.org>
+            Pádraig Brady  <P@draigBrady.com>
+
+       canonicalize-lgpl: Support the case path_max > INT_MAX.
+       * lib/canonicalize-lgpl.c (__realpath): Declare n as ssize_t, not int.
+       Fix overflow check, for platforms where 'size_t' is larger than 'long'.
+
 2016-10-13  Jim Meyering  <meyering@fb.com>
 
        getprogname: IBM z/OS: avoid NULL-dereference
index 4a38a4610ed69ba15e2bb3666561c44624200379..7f54008a74f8aed593d768a132dc9dde2ffabebf 100644 (file)
@@ -194,7 +194,6 @@ __realpath (const char *name, char *resolved)
 #else
       struct stat st;
 #endif
-      int n;
 
       /* Skip sequence of multiple path-separators.  */
       while (ISSLASH (*start))
@@ -275,6 +274,7 @@ __realpath (const char *name, char *resolved)
             {
               char *buf;
               size_t len;
+              ssize_t n;
 
               if (++num_links > MAXSYMLINKS)
                 {
@@ -311,7 +311,8 @@ __realpath (const char *name, char *resolved)
                 }
 
               len = strlen (end);
-              if ((long int) (n + len) >= path_max)
+              /* Check that n + len + 1 doesn't overflow and is <= path_max. */
+              if (n >= SIZE_MAX - len || n + len >= path_max)
                 {
                   freea (buf);
                   __set_errno (ENAMETOOLONG);