]> 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>
Sun, 18 Mar 2012 09:29:21 +0000 (18:29 +0900)
Clang Static Analyzer complaned of that.

SVN-Revision: 4121

libarchive/archive_read_support_format_7zip.c

index 53f138ea9b973527dc9a7633e4f9a10c3f62a315..0e4eb19bea09cb8702fb7b788fe99bf0609b2746 100644 (file)
@@ -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)