diff options
author | Mark Wielaard <mjw@redhat.com> | 2016-02-11 12:46:03 +0100 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2016-02-18 14:52:36 +0100 |
commit | f5622bdfe6baf19d7ea20b467bc7444dc82a53a2 (patch) | |
tree | f9bcad7e5ff6b52c64d4e7250091592cc947cfbe /libdwfl | |
parent | c1e4e29fdaa02c34a6ad5892d627274e796eaa83 (diff) | |
download | elfutils-f5622bdfe6baf19d7ea20b467bc7444dc82a53a2.tar.gz |
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 <mjw@redhat.com>
Diffstat (limited to 'libdwfl')
-rw-r--r-- | libdwfl/ChangeLog | 4 | ||||
-rw-r--r-- | libdwfl/relocate.c | 18 |
2 files changed, 16 insertions, 6 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 94c58d90..e92372a1 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,7 @@ +2016-02-11 Mark Wielaard <mjw@redhat.com> + + * relocate.c (relocate_section): Check result of gelf_update_* calls. + 2016-01-08 Mark Wielaard <mjw@redhat.com> * libdwfl_a_SOURCES: Unconditionally add gzip.c. diff --git a/libdwfl/relocate.c b/libdwfl/relocate.c index fc88df30..920ead23 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; |