From 9553a3a0e453dbc68ac9ec11dfe43c538ecd7c06 Mon Sep 17 00:00:00 2001 From: Martin Matuska Date: Mon, 6 Feb 2017 02:48:24 +0100 Subject: [PATCH] XAR reader: implement checksum_cleanup() to avoid memory leaks on error Reported-By: OSS-Fuzz issue 551 --- libarchive/archive_read_support_format_xar.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libarchive/archive_read_support_format_xar.c b/libarchive/archive_read_support_format_xar.c index d3002af71..7a22beb9d 100644 --- a/libarchive/archive_read_support_format_xar.c +++ b/libarchive/archive_read_support_format_xar.c @@ -394,6 +394,7 @@ static void checksum_update(struct archive_read *, const void *, size_t, const void *, size_t); static int checksum_final(struct archive_read *, const void *, size_t, const void *, size_t); +static void checksum_cleanup(struct archive_read *); static int decompression_init(struct archive_read *, enum enctype); static int decompress(struct archive_read *, const void **, size_t *, const void *, size_t *); @@ -923,6 +924,7 @@ xar_cleanup(struct archive_read *a) int r; xar = (struct xar *)(a->format->data); + checksum_cleanup(a); r = decompression_cleanup(a); hdlink = xar->hdlink_list; while (hdlink != NULL) { @@ -1719,6 +1721,16 @@ decompression_cleanup(struct archive_read *a) return (r); } +static void +checksum_cleanup(struct archive_read *a) { + struct xar *xar; + + xar = (struct xar *)(a->format->data); + + _checksum_final(&(xar->a_sumwrk), NULL, 0); + _checksum_final(&(xar->e_sumwrk), NULL, 0); +} + static void xmlattr_cleanup(struct xmlattr_list *list) { -- 2.47.3