]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Use st_size to size the buffer for reading a symbolic link value,
authorTim Kientzle <kientzle@gmail.com>
Thu, 25 Feb 2010 17:00:28 +0000 (12:00 -0500)
committerTim Kientzle <kientzle@gmail.com>
Thu, 25 Feb 2010 17:00:28 +0000 (12:00 -0500)
instead of using the arbitrary (and sometimes non-existent) PATH_MAX
variable.  This is part of a fix for building on HURD.

SVN-Revision: 1990

libarchive/archive_read_disk_entry_from_file.c

index 62ac671272d93af7b7f4b767af73d41352bc1762..1ae236bfd56d78d737a82adfea7c6e850301f47a 100644 (file)
@@ -181,15 +181,26 @@ archive_read_disk_entry_from_file(struct archive *_a,
 
 #ifdef HAVE_READLINK
        if (S_ISLNK(st->st_mode)) {
-               char linkbuffer[PATH_MAX + 1];
-               int lnklen = readlink(path, linkbuffer, PATH_MAX);
+               size_t linkbuffer_len = st->st_size + 1;
+               char *linkbuffer;
+               int lnklen;
+
+               linkbuffer = malloc(linkbuffer_len);
+               if (linkbuffer == NULL) {
+                       archive_set_error(&a->archive, ENOMEM,
+                           "Couldn't read link data");
+                       return (ARCHIVE_FAILED);
+               }
+               lnklen = readlink(path, linkbuffer, linkbuffer_len);
                if (lnklen < 0) {
                        archive_set_error(&a->archive, errno,
                            "Couldn't read link data");
+                       free(linkbuffer);
                        return (ARCHIVE_FAILED);
                }
                linkbuffer[lnklen] = 0;
                archive_entry_set_symlink(entry, linkbuffer);
+               free(linkbuffer);
        }
 #endif