]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
ensure ar strtab is null terminated 926/head
authorEd Maste <emaste@freebsd.org>
Fri, 21 Jul 2017 10:46:17 +0000 (06:46 -0400)
committerEd Maste <emaste@freebsd.org>
Fri, 21 Jul 2017 10:47:14 +0000 (06:47 -0400)
ar support calls strstr() on the strtab, which requres that its
arguments are null terminated.

libarchive/archive_write_set_format_ar.c

index c9771d81a128cd245ad444e6fbab0dda7c49d045..6fab9d6694b0976a1e1ac4349465e02ba0efbea2 100644 (file)
@@ -374,13 +374,14 @@ archive_write_ar_data(struct archive_write *a, const void *buff, size_t s)
                        return (ARCHIVE_WARN);
                }
 
-               ar->strtab = (char *)malloc(s);
+               ar->strtab = (char *)malloc(s + 1);
                if (ar->strtab == NULL) {
                        archive_set_error(&a->archive, ENOMEM,
                            "Can't allocate strtab buffer");
                        return (ARCHIVE_FATAL);
                }
                strncpy(ar->strtab, buff, s);
+               ar->strtab[s] = '\0';
                ar->has_strtab = 1;
        }