From: Mark Wielaard Date: Thu, 11 Feb 2016 11:46:03 +0000 (+0100) Subject: libdwfl: Check result of gelf_update_* calls in relocate_section. X-Git-Tag: elfutils-0.166~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5622bdfe6baf19d7ea20b467bc7444dc82a53a2;p=thirdparty%2Felfutils.git libdwfl: Check result of gelf_update_* calls in relocate_section. For corrupted ELF files the gelf_update calls might fail in which case it is better to immediately return an error message instead of (silently) continuing. Signed-off-by: Mark Wielaard --- diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 94c58d901..e92372a14 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,7 @@ +2016-02-11 Mark Wielaard + + * relocate.c (relocate_section): Check result of gelf_update_* calls. + 2016-01-08 Mark Wielaard * libdwfl_a_SOURCES: Unconditionally add gzip.c. diff --git a/libdwfl/relocate.c b/libdwfl/relocate.c index fc88df303..920ead23c 100644 --- a/libdwfl/relocate.c +++ b/libdwfl/relocate.c @@ -1,5 +1,5 @@ /* Relocate debug information. - Copyright (C) 2005-2011, 2014 Red Hat, Inc. + Copyright (C) 2005-2011, 2014, 2016 Red Hat, Inc. This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -605,7 +605,8 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr, case DWFL_E_NOERROR: /* We applied the relocation. Elide it. */ memset (&rel_mem, 0, sizeof rel_mem); - gelf_update_rel (reldata, relidx, &rel_mem); + if (unlikely (gelf_update_rel (reldata, relidx, &rel_mem) == 0)) + return DWFL_E_LIBELF; ++complete; break; case DWFL_E_BADRELTYPE: @@ -635,7 +636,9 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr, case DWFL_E_NOERROR: /* We applied the relocation. Elide it. */ memset (&rela_mem, 0, sizeof rela_mem); - gelf_update_rela (reldata, relidx, &rela_mem); + if (unlikely (gelf_update_rela (reldata, relidx, + &rela_mem) == 0)) + return DWFL_E_LIBELF; ++complete; break; case DWFL_E_BADRELTYPE: @@ -671,7 +674,8 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr, if (r->r_info != 0 || r->r_offset != 0) { if (next != relidx) - gelf_update_rel (reldata, next, r); + if (unlikely (gelf_update_rel (reldata, next, r) == 0)) + return DWFL_E_LIBELF; ++next; } } @@ -683,7 +687,8 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr, if (r->r_info != 0 || r->r_offset != 0 || r->r_addend != 0) { if (next != relidx) - gelf_update_rela (reldata, next, r); + if (unlikely (gelf_update_rela (reldata, next, r) == 0)) + return DWFL_E_LIBELF; ++next; } } @@ -691,7 +696,8 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr, } shdr->sh_size = reldata->d_size = nrels * sh_entsize; - gelf_update_shdr (scn, shdr); + if (unlikely (gelf_update_shdr (scn, shdr) == 0)) + return DWFL_E_LIBELF; } return result;