From: Bruno Haible Date: Fri, 14 Oct 2016 00:49:05 +0000 (+0200) Subject: canonicalize-lgpl: Support the case path_max > INT_MAX. X-Git-Tag: v1.0~6605 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=794b3480e3c1a46d23e42491c39e332ebd3ccbc8;p=gnulib.git canonicalize-lgpl: Support the case path_max > INT_MAX. * lib/canonicalize-lgpl.c (__realpath): Declare n as ssize_t, not int. --- diff --git a/ChangeLog b/ChangeLog index 5b5f81dc78..4d84310299 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-10-14 Bruno Haible + Pádraig Brady + + 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 getprogname: IBM z/OS: avoid NULL-dereference diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c index 4a38a4610e..7f54008a74 100644 --- a/lib/canonicalize-lgpl.c +++ b/lib/canonicalize-lgpl.c @@ -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);