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~2^2~204 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2a2e5f990a53ea4573cfc0f09dd42e9fff179fb;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 e211e67be..a7b0cc91b 100644 --- a/libarchive/archive_read_support_format_7zip.c +++ b/libarchive/archive_read_support_format_7zip.c @@ -1823,9 +1823,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); @@ -2318,6 +2321,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) @@ -2326,6 +2335,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)