From: Mark Wielaard Date: Wed, 6 Mar 2019 19:02:52 +0000 (+0100) Subject: libasm: Check return value of gelf_update_ehdr in asm_end. X-Git-Tag: elfutils-0.177~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff063240ac97302f289b12ac7dff655cdc0d5d70;p=thirdparty%2Felfutils.git libasm: Check return value of gelf_update_ehdr in asm_end. In theory the gelf_update_ehdr call could fail. Immediately report an error in that case. Signed-off-by: Mark Wielaard --- diff --git a/libasm/ChangeLog b/libasm/ChangeLog index 92dfd7294..05b830c86 100644 --- a/libasm/ChangeLog +++ b/libasm/ChangeLog @@ -1,3 +1,7 @@ +2019-03-06 Mark Wielaard + + * asm_end.c (binary_end): Check return value of gelf_update_ehdr. + 2018-10-19 Mark Wielaard * disasm_cb.c (read_symtab_exec): Check sh_entsize is not zero. diff --git a/libasm/asm_end.c b/libasm/asm_end.c index 5aab8dfa0..99e950170 100644 --- a/libasm/asm_end.c +++ b/libasm/asm_end.c @@ -460,7 +460,11 @@ binary_end (AsmCtx_t *ctx) else ehdr->e_shstrndx = elf_ndxscn (shstrscn); - gelf_update_ehdr (ctx->out.elf, ehdr); + if (unlikely (gelf_update_ehdr (ctx->out.elf, ehdr) == 0)) + { + __libasm_seterrno (ASM_E_LIBELF); + result = -1; + } /* Write out the ELF file. */ if (unlikely (elf_update (ctx->out.elf, ELF_C_WRITE_MMAP) < 0))