diff --git a/src/util.c b/src/util.c index 1cc08ba..eee8514 100644 --- a/src/util.c +++ b/src/util.c @@ -460,12 +460,12 @@ move_file (char const *from, bool *from_needs_removal, /* FROM contains the contents of the symlink we have patched; need to convert that back into a symlink. */ - char *buffer = xmalloc (PATH_MAX); + char *buffer = xmalloc (fromst->st_size + 1); int fd, size = 0, i; if ((fd = safe_open (from, O_RDONLY | O_BINARY, 0)) < 0) pfatal ("Can't reopen file %s", quotearg (from)); - while ((i = read (fd, buffer + size, PATH_MAX - size)) > 0) + while ((i = read (fd, buffer + size, fromst->st_size - size)) > 0) size += i; if (i != 0 || close (fd) != 0) read_fatal (); @@ -610,10 +610,10 @@ copy_file (char const *from, char const *to, struct stat *tost, if (S_ISLNK (mode)) { - char *buffer = xmalloc (PATH_MAX + 1); + char *buffer = xmalloc (tost->st_size + 2); ssize_t r; - if ((r = safe_readlink (from, buffer, PATH_MAX)) < 0) + if ((r = safe_readlink (from, buffer, tost->st_size)) < 0) pfatal ("Can't read %s %s", "symbolic link", from); buffer[r] = '\0'; if (safe_symlink (buffer, to) != 0)