1 See <http://lists.gnu.org/archive/html/bug-patch/2015-06/msg00009.html>
3 From 0507dfad5f060161f01840067e1bb1615257b636 Mon Sep 17 00:00:00 2001
4 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
5 Date: Mon, 8 Jun 2015 17:27:56 +0200
6 Subject: [PATCH] Do not rely on PATH_MAX when reading a symlink target.
8 * src/util.c (move_file, copy_file): Use 'fromst->st_size + 1' and
9 'tost->st_size + 1' for the allocation, and 'fromst->st_size' and
10 'tost->st_size' instead of PATH_MAX. Fixes compilation on GNU/Hurd.
12 src/util.c | 8 ++++----
13 1 file changed, 4 insertions(+), 4 deletions(-)
15 diff --git a/src/util.c b/src/util.c
16 index 1cc08ba..67dbd3a 100644
19 @@ -460,12 +460,12 @@ move_file (char const *from, bool *from_needs_removal,
21 /* FROM contains the contents of the symlink we have patched; need
22 to convert that back into a symlink. */
23 - char *buffer = xmalloc (PATH_MAX);
24 + char *buffer = xmalloc (fromst->st_size + 1);
27 if ((fd = safe_open (from, O_RDONLY | O_BINARY, 0)) < 0)
28 pfatal ("Can't reopen file %s", quotearg (from));
29 - while ((i = read (fd, buffer + size, PATH_MAX - size)) > 0)
30 + while ((i = read (fd, buffer + size, fromst->st_size - size)) > 0)
32 if (i != 0 || close (fd) != 0)
34 @@ -610,10 +610,10 @@ copy_file (char const *from, char const *to, struct stat *tost,
38 - char *buffer = xmalloc (PATH_MAX + 1);
39 + char *buffer = xmalloc (tost->st_size + 1);
42 - if ((r = safe_readlink (from, buffer, PATH_MAX)) < 0)
43 + if ((r = safe_readlink (from, buffer, tost->st_size)) < 0)
44 pfatal ("Can't read %s %s", "symbolic link", from);
46 if (safe_symlink (buffer, to) != 0)