]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Avoid an extra copy of a symbolic-link name by using archive_entry_copy_symlink_l...
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Thu, 22 Dec 2011 17:22:48 +0000 (12:22 -0500)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Thu, 22 Dec 2011 17:22:48 +0000 (12:22 -0500)
instead of archive_entry_copy_symlink.

SVN-Revision: 3964

libarchive/archive_read_support_format_zip.c

index a061773ca82846b635c46942ea551797d3c154bf..a8124223bc807d88c03dea845518dc5714f0149d 100644 (file)
@@ -362,29 +362,25 @@ archive_read_format_zip_seekable_read_header(struct archive_read *a,
        if (r != ARCHIVE_OK)
                return r;
        if ((zip->entry->mode & AE_IFMT) == AE_IFLNK) {
-               char *linkname;
                const void *p;
                size_t linkname_length = archive_entry_size(entry);
 
-               linkname = malloc(linkname_length + 1);
-               if (!linkname) {
-                       archive_set_error(&a->archive, ENOMEM, "Out  of memory");
-                       return ARCHIVE_FATAL;
-               }
-
                archive_entry_set_size(entry, 0);
                p = __archive_read_ahead(a, linkname_length, NULL);
                if (p == NULL) {
-                       free(linkname);
                        archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
                            "Truncated Zip file");
                        return ARCHIVE_FATAL;
                }
 
-               memcpy(linkname, p, linkname_length);
-               linkname[linkname_length] = '\0';
-               archive_entry_copy_symlink(entry, linkname);
-               free(linkname);
+               if (archive_entry_copy_symlink_l(entry, p, linkname_length,
+                   NULL) != 0) {
+                       /* NOTE: If the last argument is NULL, this will
+                        * fail only by memeory allocation failure. */
+                       archive_set_error(&a->archive, ENOMEM,
+                           "Can't allocate memory for Symlink");
+                       return (ARCHIVE_FATAL);
+               }
                /* TODO: handle character-set issues? */
        }
        return ARCHIVE_OK;