aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2016-06-19 22:58:10 -0400
committerMike Frysinger <vapier@gentoo.org>2016-06-19 22:58:10 -0400
commit4c6b85b04291c96c45cdccf7cb9147f9307e3218 (patch)
treeb7da907f58c6af49b0e2f11e9b159db791e98cc7
parentpspax: rewrite core loop to use *at funcs (diff)
downloadpax-utils-4c6b85b04291c96c45cdccf7cb9147f9307e3218.tar.gz
pax-utils-4c6b85b04291c96c45cdccf7cb9147f9307e3218.tar.bz2
pax-utils-4c6b85b04291c96c45cdccf7cb9147f9307e3218.zip
paxmacho: fix mem leak when reading macho files
-rw-r--r--paxmacho.c12
1 files 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 */