Hi,

If pathconf (name, _PC_PATH_MAX) returns a PATH_MAX value > 2 GB,
the readlink call in canonicalize-lgpl.c line 292 may return a length > 2 GB,
therefore the implicit cast (assignment) to 'int' will produce a wrong value.

If you agree with this patch, it'd be a good idea to propagate it into glibc
(it's the file stdlib/canonicalize.c there).

Bruno
>From 96e593071d8759a604e59a2b5e118e52c28fb063 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 14 Oct 2016 02:49:05 +0200
Subject: [PATCH] canonicalize-lgpl: Support the case path_max > INT_MAX.

* lib/canonicalize-lgpl.c (__realpath): Declare n as ssize_t, not int.
---
 ChangeLog               | 5 +++++
 lib/canonicalize-lgpl.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 32bddf8..ac0b277 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-10-14  Bruno Haible  <br...@clisp.org>
+
+	canonicalize-lgpl: Support the case path_max > INT_MAX.
+	* lib/canonicalize-lgpl.c (__realpath): Declare n as ssize_t, not int.
+
 2016-10-13  Paul Eggert  <egg...@cs.ucla.edu>
 
 	stdint: port SIZE_MAX to glibc s390
diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c
index 4a38a46..d3f123c 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)
                 {
-- 
2.6.4

Reply via email to