[COMMITTED] libasm: Fix double fclose in asm_end.
GCC10 -fanalyzer found a double fclose in asm_end. asm_end can call text_end, which calls fclose and checks for errors, then asm_end calls __libasm_finictx which can call fclose again (but doesn't check for errors). Call fflush in text_end instead. fflush will generate the same error fclose would if something went wrong writing out the file. Signed-off-by: Mark Wielaard --- libasm/ChangeLog | 4 libasm/asm_end.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libasm/ChangeLog b/libasm/ChangeLog index 7b0d3df3..2c092abe 100644 --- a/libasm/ChangeLog +++ b/libasm/ChangeLog @@ -1,3 +1,7 @@ +2020-04-25 Mark Wielaard + + * asm_end.c (text_end): Call fflush instead of fclose. + 2020-01-08 Mark Wielaard * libasm.h: Don't include libebl.h. Define an opaque Ebl handle. diff --git a/libasm/asm_end.c b/libasm/asm_end.c index 99e95017..3b8582fd 100644 --- a/libasm/asm_end.c +++ b/libasm/asm_end.c @@ -47,7 +47,7 @@ static int text_end (AsmCtx_t *ctx __attribute__ ((unused))) { - if (fclose (ctx->out.file) != 0) + if (fflush (ctx->out.file) != 0) { __libasm_seterrno (ASM_E_IOERROR); return -1; -- 2.18.2
[COMMITTED] libdw: Call Dwarf oom_handler() when malloc fails in __libdw_alloc_tail.
GCC10 -fanalyzer found a possibly-NULL dereference after a failed malloc in __libdw_alloc_tail. In this case we should call the Dwarf oom_handler as is done in other places where an essential malloc call fails. The oom_handler cannot return and will likely just abort. Signed-off-by: Mark Wielaard --- libdw/ChangeLog | 5 + libdw/libdw_alloc.c | 5 + 2 files changed, 10 insertions(+) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 39730fbc..75fc8f06 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,8 @@ +2020-04-25 Mark Wielaard + + * libdw_alloc.c (__libdw_alloc_tail): Call Dwarf oom_handler() + when malloc fails. + 2020-04-17 Mark Wielaard * dwarf_begin_elf.c (check_section): Handle .gnu.debuglto_ prefix. diff --git a/libdw/libdw_alloc.c b/libdw/libdw_alloc.c index e0281a3d..b3e53343 100644 --- a/libdw/libdw_alloc.c +++ b/libdw/libdw_alloc.c @@ -87,6 +87,11 @@ __libdw_alloc_tail (Dwarf *dbg) if (result == NULL) { result = malloc (dbg->mem_default_size); + if (result == NULL) + { + pthread_rwlock_unlock (&dbg->mem_rwl); + dbg->oom_handler(); + } result->size = dbg->mem_default_size - offsetof (struct libdw_memblock, mem); result->remaining = result->size; -- 2.18.2
[COMMITTED] libdwfl: Fix double free on failure path in gzip.c.
GCC10 -fanalyzer found a double free when openstream failed. When openstream fails __libdw_gunzip will call fail, which frees the state->buffer. But openstream can call zlib_fail, which will also call fail. Instead of calling zlib_fail, just return the error that zlib_fail would have returned. Signed-off-by: Mark Wielaard --- libdwfl/ChangeLog | 5 + libdwfl/gzip.c| 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 4ddc9ad4..daedaed8 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2020-04-25 Mark Wielaard + + * gzip.c (open_stream): Return DWFL_E_NOMEM instead of calling + zlib_fail. + 2020-04-16 Mark Wielaard * find-debuginfo.c (dwfl_standard_find_debuginfo): Initialize bits diff --git a/libdwfl/gzip.c b/libdwfl/gzip.c index 043d0b6e..e9988cc2 100644 --- a/libdwfl/gzip.c +++ b/libdwfl/gzip.c @@ -153,7 +153,7 @@ open_stream (int fd, off_t start_offset, struct unzip_state *state) if (unlikely (state->zf == NULL)) { close (d); - return zlib_fail (state, Z (MEM_ERROR)); + return DWFL_E_NOMEM; } /* From here on, zlib will close D. */ -- 2.18.2