summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2016-02-11 13:20:59 +0100
committerMark Wielaard <mjw@redhat.com>2016-02-18 14:52:36 +0100
commit02c48ac64ee068e9a72d987996f3cbf5213ee13a (patch)
treef040a438b96c003fa7c20547da0a1191a09a2009 /libdwfl
parentf5622bdfe6baf19d7ea20b467bc7444dc82a53a2 (diff)
libdwfl: Check result of gelf_get* calls in relocate.c
For corrupted ELF files gelf_get calls might fail in which case it is better to immediately return an error instead of using the NULL result and crashing. Signed-off-by: Mark Wielaard <mjw@redhat.com>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog6
-rw-r--r--libdwfl/relocate.c26
2 files changed, 26 insertions, 6 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index e92372a1..cc8eec7d 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,11 @@
2016-02-11 Mark Wielaard <mjw@redhat.com>
+ * relocate.c (relocate_section): Check result of all gelf_get* calls.
+ (__libdwfl_relocate): Likewise.
+ (__libdwfl_relocate_section): Likewise.
+
+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>
diff --git a/libdwfl/relocate.c b/libdwfl/relocate.c
index 920ead23..a44126e8 100644
--- a/libdwfl/relocate.c
+++ b/libdwfl/relocate.c
@@ -671,6 +671,8 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
{
GElf_Rel rel_mem;
GElf_Rel *r = gelf_getrel (reldata, relidx, &rel_mem);
+ if (unlikely (r == NULL))
+ return DWFL_E_LIBELF;
if (r->r_info != 0 || r->r_offset != 0)
{
if (next != relidx)
@@ -684,6 +686,8 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
{
GElf_Rela rela_mem;
GElf_Rela *r = gelf_getrela (reldata, relidx, &rela_mem);
+ if (unlikely (r == NULL))
+ return DWFL_E_LIBELF;
if (r->r_info != 0 || r->r_offset != 0 || r->r_addend != 0)
{
if (next != relidx)
@@ -729,6 +733,8 @@ __libdwfl_relocate (Dwfl_Module *mod, Elf *debugfile, bool debug)
{
GElf_Shdr shdr_mem;
GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
+ if (unlikely (shdr == NULL))
+ return DWFL_E_LIBELF;
if ((shdr->sh_type == SHT_REL || shdr->sh_type == SHT_RELA)
&& shdr->sh_size != 0)
@@ -762,10 +768,18 @@ __libdwfl_relocate_section (Dwfl_Module *mod, Elf *relocated,
if (elf_getshdrstrndx (relocated, &shstrndx) < 0)
return DWFL_E_LIBELF;
- return (__libdwfl_module_getebl (mod)
- ?: relocate_section (mod, relocated,
- gelf_getehdr (relocated, &ehdr_mem), shstrndx,
- &reloc_symtab,
- relocscn, gelf_getshdr (relocscn, &shdr_mem),
- tscn, false, partial));
+ Dwfl_Error result = __libdwfl_module_getebl (mod);
+ if (unlikely (result != DWFL_E_NOERROR))
+ return result;
+
+ GElf_Ehdr *ehdr = gelf_getehdr (relocated, &ehdr_mem);
+ if (unlikely (ehdr == NULL))
+ return DWFL_E_LIBELF;
+
+ GElf_Shdr *shdr = gelf_getshdr (relocscn, &shdr_mem);
+ if (unlikely (shdr == NULL))
+ return DWFL_E_LIBELF;
+
+ return relocate_section (mod, relocated, ehdr, shstrndx, &reloc_symtab,
+ relocscn, shdr, tscn, false, partial);
}