diff options
Diffstat (limited to 'libdwfl/open.c')
-rw-r--r-- | libdwfl/open.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/libdwfl/open.c b/libdwfl/open.c index ca6b862f..0ab2a9d2 100644 --- a/libdwfl/open.c +++ b/libdwfl/open.c @@ -64,18 +64,19 @@ /* Always consumes *ELF, never consumes FD. Replaces *ELF on success. */ static Dwfl_Error -decompress (int fd, Elf **elf) +decompress (int fd __attribute__ ((unused)), Elf **elf) { Dwfl_Error error = DWFL_E_BADELF; + void *buffer = NULL; + size_t size = 0; #if USE_ZLIB || USE_BZLIB - void *buffer; - size_t size; - const off64_t offset = (*elf)->start_offset; void *const mapped = ((*elf)->map_address == NULL ? NULL : (*elf)->map_address + (*elf)->start_offset); const size_t mapped_size = (*elf)->maximum_size; + if (mapped_size == 0) + return error; error = __libdw_gunzip (fd, offset, mapped, mapped_size, &buffer, &size); if (error == DWFL_E_BADELF) @@ -87,14 +88,22 @@ decompress (int fd, Elf **elf) if (error == DWFL_E_NOERROR) { - *elf = elf_memory (buffer, size); - if (*elf == NULL) + if (unlikely (size == 0)) { - error = DWFL_E_LIBELF; + error = DWFL_E_BADELF; free (buffer); } else - (*elf)->flags |= ELF_F_MALLOCED; + { + *elf = elf_memory (buffer, size); + if (*elf == NULL) + { + error = DWFL_E_LIBELF; + free (buffer); + } + else + (*elf)->flags |= ELF_F_MALLOCED; + } } return error; |