]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
warc: Check realloc return value (#2144)
authorTobias Stoeckmann <stoeckmann@users.noreply.github.com>
Thu, 25 Apr 2024 09:20:23 +0000 (09:20 +0000)
committerGitHub <noreply@github.com>
Thu, 25 Apr 2024 09:20:23 +0000 (11:20 +0200)
Since realloc could fail, check its return value and set a proper error
message.

libarchive/archive_read_support_format_warc.c

index c49d44eba5e540f30aaa2bd6bff03dd9dae476a3..fcec5bc4cbb9cb0db0a5294f05964345053d63eb 100644 (file)
@@ -215,6 +215,7 @@ _warc_rdhdr(struct archive_read *a, struct archive_entry *entry)
        const char *buf;
        ssize_t nrd;
        const char *eoh;
+       char *tmp;
        /* for the file name, saves some strndup()'ing */
        warc_string_t fnam;
        /* warc record type, not that we really use it a lot */
@@ -321,7 +322,14 @@ start_over:
                 * malloc()+free() roundtrip */
                if (fnam.len + 1U > w->pool.len) {
                        w->pool.len = ((fnam.len + 64U) / 64U) * 64U;
-                       w->pool.str = realloc(w->pool.str, w->pool.len);
+                       tmp = realloc(w->pool.str, w->pool.len);
+                       if (tmp == NULL) {
+                               archive_set_error(
+                                       &a->archive, ENOMEM,
+                                       "Out of memory");
+                               return (ARCHIVE_FATAL);
+                       }
+                       w->pool.str = tmp;
                }
                memcpy(w->pool.str, fnam.str, fnam.len);
                w->pool.str[fnam.len] = '\0';