]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Avoid possibility to pass zero to the first argument of calloc().
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Wed, 11 Jan 2012 01:02:23 +0000 (20:02 -0500)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Wed, 11 Jan 2012 01:02:23 +0000 (20:02 -0500)
Clang Static Analyzer complaned of that.

SVN-Revision: 4121

libarchive/archive_read_support_format_7zip.c

index e211e67bedb0efe366e2517180e8f61ef40a0b5b..a7b0cc91b78b62211fb634833f66657f13dfc487 100644 (file)
@@ -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)