From: Michihiro NAKAJIMA Date: Wed, 11 Jan 2012 01:02:23 +0000 (-0500) Subject: Avoid possibility to pass zero to the first argument of calloc(). X-Git-Tag: v3.0.4~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=158bb528ab21733ebd11dab7c0cf331b899ed73a;p=thirdparty%2Flibarchive.git Avoid possibility to pass zero to the first argument of calloc(). Clang Static Analyzer complaned of that. SVN-Revision: 4121 --- diff --git a/libarchive/archive_read_support_format_7zip.c b/libarchive/archive_read_support_format_7zip.c index 53f138ea9..0e4eb19be 100644 --- a/libarchive/archive_read_support_format_7zip.c +++ b/libarchive/archive_read_support_format_7zip.c @@ -1827,9 +1827,12 @@ read_Folder(struct archive_read *a, struct _7z_folder *f) f->numBindPairs = numOutStreamsTotal - 1; if (zip->header_bytes_remaining < f->numBindPairs) return (-1); - f->bindPairs = calloc(f->numBindPairs, sizeof(*f->bindPairs)); - if (f->bindPairs == NULL) - return (-1); + if (f->numBindPairs > 0) { + f->bindPairs = calloc(f->numBindPairs, sizeof(*f->bindPairs)); + if (f->bindPairs == NULL) + return (-1); + } else + f->bindPairs = NULL; for (i = 0; i < f->numBindPairs; i++) { if (parse_7zip_uint64(a, &(f->bindPairs[i].inIndex)) < 0) return (-1); @@ -2322,6 +2325,12 @@ read_Header(struct archive_read *a, struct _7z_header_info *h, } break; case kEmptyFile: + if (empty_streams <= 0) { + /* Unexcepted sequence. Skip this. */ + if (header_bytes(a, ll) == NULL) + return (-1); + break; + } h->emptyFileBools = calloc(empty_streams, sizeof(*h->emptyFileBools)); if (h->emptyFileBools == NULL) @@ -2330,6 +2339,12 @@ read_Header(struct archive_read *a, struct _7z_header_info *h, return (-1); break; case kAnti: + if (empty_streams <= 0) { + /* Unexcepted sequence. Skip this. */ + if (header_bytes(a, ll) == NULL) + return (-1); + break; + } h->antiBools = calloc(empty_streams, sizeof(*h->antiBools)); if (h->antiBools == NULL)