commit: 4c6b85b04291c96c45cdccf7cb9147f9307e3218
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 20 02:58:10 2016 +0000
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> 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 */