diff --git a/cpio/cpio.c b/cpio/cpio.c index 6696bb5..5beedd0 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -744,10 +744,8 @@ file_to_archive(struct cpio *cpio, const char *srcpath) } if (cpio->option_rename) destpath = cpio_rename(destpath); - if (destpath == NULL) { - archive_entry_free(entry); + if (destpath == NULL) return (0); - } archive_entry_copy_pathname(entry, destpath); /* diff --git a/libarchive/archive_acl.c b/libarchive/archive_acl.c index 503f379..b8b6b63 100644 --- a/libarchive/archive_acl.c +++ b/libarchive/archive_acl.c @@ -753,10 +753,8 @@ archive_acl_to_text_w(struct archive_acl *acl, ssize_t *text_len, int flags, append_entry_w(&wp, prefix, ap->type, ap->tag, flags, wname, ap->permset, id); count++; - } else if (r < 0 && errno == ENOMEM) { - free(ws); + } else if (r < 0 && errno == ENOMEM) return (NULL); - } } /* Add terminating character */ @@ -977,10 +975,8 @@ archive_acl_to_text_l(struct archive_acl *acl, ssize_t *text_len, int flags, prefix = NULL; r = archive_mstring_get_mbs_l( &ap->name, &name, &len, sc); - if (r != 0) { - free(s); + if (r != 0) return (NULL); - } if (count > 0) *p++ = separator; if (name == NULL || diff --git a/libarchive/archive_read_support_format_7zip.c b/libarchive/archive_read_support_format_7zip.c index a5c66e4..3387eaf 100644 --- a/libarchive/archive_read_support_format_7zip.c +++ b/libarchive/archive_read_support_format_7zip.c @@ -2977,7 +2977,13 @@ get_uncompressed_data(struct archive_read *a, const void **buff, size_t size, if (zip->codec == _7Z_COPY && zip->codec2 == (unsigned long)-1) { /* Copy mode. */ - *buff = __archive_read_ahead(a, minimum, &bytes_avail); + /* + * Note: '1' here is a performance optimization. + * Recall that the decompression layer returns a count of + * available bytes; asking for more than that forces the + * decompressor to combine reads by copying data. + */ + *buff = __archive_read_ahead(a, 1, &bytes_avail); if (bytes_avail <= 0) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, diff --git a/libarchive/archive_read_support_format_iso9660.c b/libarchive/archive_read_support_format_iso9660.c index 8fa471d..f01d37b 100644 --- a/libarchive/archive_read_support_format_iso9660.c +++ b/libarchive/archive_read_support_format_iso9660.c @@ -2097,7 +2097,6 @@ parse_rockridge(struct archive_read *a, struct file_info *file, const unsigned char *p, const unsigned char *end) { struct iso9660 *iso9660; - int entry_seen = 0; iso9660 = (struct iso9660 *)(a->format->data); @@ -2253,16 +2252,8 @@ parse_rockridge(struct archive_read *a, struct file_info *file, } p += p[2]; - entry_seen = 1; - } - - if (entry_seen) - return (ARCHIVE_OK); - else { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Tried to parse Rockridge extensions, but none found"); - return (ARCHIVE_WARN); } + return (ARCHIVE_OK); } static int diff --git a/libarchive/archive_read_support_format_lha.c b/libarchive/archive_read_support_format_lha.c index 95c99bb..b8ef4ae 100644 --- a/libarchive/archive_read_support_format_lha.c +++ b/libarchive/archive_read_support_format_lha.c @@ -701,12 +701,6 @@ archive_read_format_lha_read_header(struct archive_read *a, * Prepare variables used to read a file content. */ lha->entry_bytes_remaining = lha->compsize; - if (lha->entry_bytes_remaining < 0) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Invalid LHa entry size"); - return (ARCHIVE_FATAL); - } lha->entry_offset = 0; lha->entry_crc_calculated = 0; diff --git a/libarchive/archive_read_support_format_rar.c b/libarchive/archive_read_support_format_rar.c index b84b607..cbb14c3 100644 --- a/libarchive/archive_read_support_format_rar.c +++ b/libarchive/archive_read_support_format_rar.c @@ -258,7 +258,6 @@ struct rar struct data_block_offsets *dbo; unsigned int cursor; unsigned int nodes; - char filename_must_match; /* LZSS members */ struct huffman_code maincode; @@ -1038,10 +1037,8 @@ archive_read_format_rar_read_data(struct archive_read *a, const void **buff, case COMPRESS_METHOD_GOOD: case COMPRESS_METHOD_BEST: ret = read_data_compressed(a, buff, size, offset); - if (ret != ARCHIVE_OK && ret != ARCHIVE_WARN) { + if (ret != ARCHIVE_OK && ret != ARCHIVE_WARN) __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc); - rar->start_new_table = 1; - } break; default: @@ -1573,12 +1570,6 @@ read_header(struct archive_read *a, struct archive_entry *entry, } return ret; } - else if (rar->filename_must_match) - { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Mismatch of file parts split across multi-volume archive"); - return (ARCHIVE_FATAL); - } rar->filename_save = (char*)realloc(rar->filename_save, filename_size + 1); @@ -2319,11 +2310,6 @@ parse_codes(struct archive_read *a) new_size = DICTIONARY_MAX_SIZE; else new_size = rar_fls((unsigned int)rar->unp_size) << 1; - if (new_size == 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Zero window size is invalid."); - return (ARCHIVE_FATAL); - } new_window = realloc(rar->lzss.window, new_size); if (new_window == NULL) { archive_set_error(&a->archive, ENOMEM, @@ -2952,14 +2938,12 @@ rar_read_ahead(struct archive_read *a, size_t min, ssize_t *avail) else if (*avail == 0 && rar->main_flags & MHD_VOLUME && rar->file_flags & FHD_SPLIT_AFTER) { - rar->filename_must_match = 1; ret = archive_read_format_rar_read_header(a, a->entry); if (ret == (ARCHIVE_EOF)) { rar->has_endarc_header = 1; ret = archive_read_format_rar_read_header(a, a->entry); } - rar->filename_must_match = 0; if (ret != (ARCHIVE_OK)) return NULL; return rar_read_ahead(a, min, avail); diff --git a/libarchive/archive_write_set_format_iso9660.c b/libarchive/archive_write_set_format_iso9660.c index badc88b..c0ca435 100644 --- a/libarchive/archive_write_set_format_iso9660.c +++ b/libarchive/archive_write_set_format_iso9660.c @@ -4899,10 +4899,10 @@ isofile_gen_utility_names(struct archive_write *a, struct isofile *file) if (p[0] == '/') { if (p[1] == '/') /* Convert '//' --> '/' */ - memmove(p, p+1, strlen(p+1) + 1); + strcpy(p, p+1); else if (p[1] == '.' && p[2] == '/') /* Convert '/./' --> '/' */ - memmove(p, p+2, strlen(p+2) + 1); + strcpy(p, p+2); else if (p[1] == '.' && p[2] == '.' && p[3] == '/') { /* Convert 'dir/dir1/../dir2/' * --> 'dir/dir2/' diff --git a/libarchive/archive_write_set_format_mtree.c b/libarchive/archive_write_set_format_mtree.c index 0f2431e..493d473 100644 --- a/libarchive/archive_write_set_format_mtree.c +++ b/libarchive/archive_write_set_format_mtree.c @@ -1810,10 +1810,10 @@ mtree_entry_setup_filenames(struct archive_write *a, struct mtree_entry *file, if (p[0] == '/') { if (p[1] == '/') /* Convert '//' --> '/' */ - memmove(p, p+1, strlen(p+1) + 1); + strcpy(p, p+1); else if (p[1] == '.' && p[2] == '/') /* Convert '/./' --> '/' */ - memmove(p, p+2, strlen(p+2) + 1); + strcpy(p, p+2); else if (p[1] == '.' && p[2] == '.' && p[3] == '/') { /* Convert 'dir/dir1/../dir2/' * --> 'dir/dir2/' diff --git a/libarchive/archive_write_set_format_pax.c b/libarchive/archive_write_set_format_pax.c index 4863e46..0eaf733 100644 --- a/libarchive/archive_write_set_format_pax.c +++ b/libarchive/archive_write_set_format_pax.c @@ -522,13 +522,11 @@ add_pax_acl(struct archive_write *a, ARCHIVE_ERRNO_FILE_FORMAT, "%s %s %s", "Can't translate ", attr, " to UTF-8"); return(ARCHIVE_WARN); - } - - if (*p != '\0') { + } else if (*p != '\0') { add_pax_attr(&(pax->pax_header), attr, p); + free(p); } - free(p); return(ARCHIVE_OK); } diff --git a/libarchive/archive_write_set_format_xar.c b/libarchive/archive_write_set_format_xar.c index 56cd33c..495f0d4 100644 --- a/libarchive/archive_write_set_format_xar.c +++ b/libarchive/archive_write_set_format_xar.c @@ -2120,10 +2120,10 @@ file_gen_utility_names(struct archive_write *a, struct file *file) if (p[0] == '/') { if (p[1] == '/') /* Convert '//' --> '/' */ - memmove(p, p+1, strlen(p+1) + 1); + strcpy(p, p+1); else if (p[1] == '.' && p[2] == '/') /* Convert '/./' --> '/' */ - memmove(p, p+2, strlen(p+2) + 1); + strcpy(p, p+2); else if (p[1] == '.' && p[2] == '.' && p[3] == '/') { /* Convert 'dir/dir1/../dir2/' * --> 'dir/dir2/' @@ -3169,10 +3169,8 @@ save_xattrs(struct archive_write *a, struct file *file) checksum_update(&(xar->a_sumwrk), xar->wbuff, size); if (write_to_temp(a, xar->wbuff, size) - != ARCHIVE_OK) { - free(heap); - return (ARCHIVE_FATAL); - } + != ARCHIVE_OK) + return (ARCHIVE_FATAL); if (r == ARCHIVE_OK) { xar->stream.next_out = xar->wbuff; xar->stream.avail_out = sizeof(xar->wbuff); diff --git a/tar/write.c b/tar/write.c index 63c619c..9c24566 100644 --- a/tar/write.c +++ b/tar/write.c @@ -540,7 +540,8 @@ write_archive(struct archive *a, struct bsdtar *bsdtar) lafe_warnc(archive_errno(disk), "%s", archive_error_string(disk)); bsdtar->return_value = 1; - goto next_entry; + archive_entry_free(entry); + continue; } /* @@ -556,14 +557,15 @@ write_archive(struct archive *a, struct bsdtar *bsdtar) "%s", archive_error_string(disk)); if (r == ARCHIVE_FATAL) bsdtar->return_value = 1; - archive_read_close(disk); - goto next_entry; + else + archive_read_close(disk); + archive_entry_free(entry); + continue; } write_file(bsdtar, a, entry); - archive_read_close(disk); -next_entry: archive_entry_free(entry); + archive_read_close(disk); entry = NULL; archive_entry_linkify(bsdtar->resolver, &entry, &sparse_entry); }