]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwfl: Check result of gelf_update_* calls in relocate_section.
authorMark Wielaard <mjw@redhat.com>
Thu, 11 Feb 2016 11:46:03 +0000 (12:46 +0100)
committerMark Wielaard <mjw@redhat.com>
Thu, 18 Feb 2016 13:52:36 +0000 (14:52 +0100)
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>
libdwfl/ChangeLog
libdwfl/relocate.c

index 94c58d901b3561939f054c1a94af9c3b44290cb4..e92372a140e9be9cebca9deb0677b138f8105ee6 100644 (file)
@@ -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.
index fc88df303581a807cfdb064c9a70de10a6fb1e47..920ead23cf1dc7f0e6bdb9d25769e6728d0874b6 100644 (file)
@@ -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;