From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 02A641382AC for ; Mon, 20 Jun 2016 03:08:29 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 32084141B2; Mon, 20 Jun 2016 03:08:26 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 9000114232 for ; Mon, 20 Jun 2016 03:08:25 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 28577340862 for ; Mon, 20 Jun 2016 03:08:24 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id DA489241E for ; Mon, 20 Jun 2016 03:08:21 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1466391490.4c6b85b04291c96c45cdccf7cb9147f9307e3218.vapier@gentoo> Subject: [gentoo-commits] proj/pax-utils:master commit in: / X-VCS-Repository: proj/pax-utils X-VCS-Files: paxmacho.c X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 4c6b85b04291c96c45cdccf7cb9147f9307e3218 X-VCS-Branch: master Date: Mon, 20 Jun 2016 03:08:21 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: d1fa4b40-6628-4cd4-b1c5-ad2433835140 X-Archives-Hash: 8c43b43bed3f1ab3b6f33041d4e37c54 commit: 4c6b85b04291c96c45cdccf7cb9147f9307e3218 Author: Mike Frysinger gentoo org> AuthorDate: Mon Jun 20 02:58:10 2016 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Mon Jun 20 02:58:10 2016 +0000 URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=4c6b85b0 paxmacho: fix mem leak when reading macho files paxmacho.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/paxmacho.c b/paxmacho.c index 84aeb86..090fc18 100644 --- a/paxmacho.c +++ b/paxmacho.c @@ -247,7 +247,7 @@ fatobj *readmacho_buffer(const char *filename, char *buffer, size_t buffer_len) /* make sure we have enough bytes to scan */ if (ret->len <= sizeof(struct fat_header)) - return NULL; + goto fail; fhdr = ret->data; /* Check what kind of file this is. Unfortunately we don't have @@ -276,14 +276,14 @@ fatobj *readmacho_buffer(const char *filename, char *buffer, size_t buffer_len) * beware of corrupt files and Java bytecode which shares * the same magic with us :( */ if (sizeof(struct fat_arch) * narchs > bufleft) - return NULL; + goto fail; for (i = 1; i <= narchs; i++) { farch = (struct fat_arch *)dptr; offset = MGET(swapped, farch->offset); if (offset + sizeof(struct mach_header) >= bufleft || read_mach_header(fobj, ret->data + offset) == 0) - return NULL; + goto fail; if (i < narchs) { fobj = fobj->next = xzalloc(sizeof(*fobj)); /* filename and size are necessary for printing */ @@ -300,11 +300,15 @@ fatobj *readmacho_buffer(const char *filename, char *buffer, size_t buffer_len) /* simple Mach-O file, treat as single arch FAT file */ if (ret->len < sizeof(struct mach_header) || read_mach_header(ret, ret->data) == 0) - return NULL; + goto fail; ret->next = NULL; } return ret; + + fail: + free(ret); + return NULL; } /* undo the readmacho() stuff */