]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Check elf_strptr didn't fail getting section name.
authorMark Wielaard <mjw@redhat.com>
Mon, 17 Nov 2014 22:15:45 +0000 (23:15 +0100)
committerMark Wielaard <mjw@redhat.com>
Mon, 17 Nov 2014 22:19:03 +0000 (23:19 +0100)
Since elf_strptr can fail and return NULL we should always check the result
before usage. Debug sections are only handled by section name, so make sure
the name actually exists.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
backends/ChangeLog
backends/ppc64_init.c
libebl/ChangeLog
libebl/ebldebugscnp.c
libelf/ChangeLog
libelf/elf-knowledge.h
src/ChangeLog
src/elfcmp.c
src/objdump.c
src/size.c

index 82a2bf1595fb59dfbb67dff7096710256ea3e655..abd22bf8896161d6b02bc4e40bb268f4885a1f4a 100644 (file)
@@ -1,3 +1,7 @@
+2014-11-17  Mark Wielaard  <mjw@redhat.com>
+
+       * ppc64_init.c (ppc64_init): Check section name is not NULL.
+
 2014-10-06  Mark Wielaard  <mjw@redhat.com>
 
        * libebl_CPU.h (dwarf_peel_type): Removed.
index 7ea2b2363f73f36492cae849fec1c8e6cc585f7b..56e1828efb56e3f131ec047385c3c04394aab1fd 100644 (file)
@@ -90,13 +90,16 @@ ppc64_init (elf, machine, eh, ehlen)
              if (opd_shdr != NULL
                  && (opd_shdr->sh_flags & SHF_ALLOC) != 0
                  && opd_shdr->sh_type == SHT_PROGBITS
-                 && opd_shdr->sh_size > 0
-                 && strcmp (elf_strptr (elf, ehdr->e_shstrndx,
-                                        opd_shdr->sh_name), ".opd") == 0)
+                 && opd_shdr->sh_size > 0)
                {
-                 eh->fd_addr = opd_shdr->sh_addr;
-                 eh->fd_data = elf_getdata (scn, NULL);
-                 break;
+                 const char *name = elf_strptr (elf, ehdr->e_shstrndx,
+                                                opd_shdr->sh_name);
+                 if (name != NULL && strcmp (name, ".opd") == 0)
+                   {
+                     eh->fd_addr = opd_shdr->sh_addr;
+                     eh->fd_data = elf_getdata (scn, NULL);
+                     break;
+                   }
                }
            }
        }
index 5ec710166287eea05da0155b9d339a308c38a3b7..b6a0e6323e3b3705858f2a009a3dc4c114f56bc6 100644 (file)
@@ -1,3 +1,7 @@
+2014-11-17  Mark Wielaard  <mjw@redhat.com>
+
+       * ebldebugscnp.c (ebl_debugscn_p): Check name is not NULL.
+
 2014-06-17  Mark Wielaard  <mjw@redhat.com>
 
        * eblinitreg.c (ebl_func_addr_mask): New function.
index f2351e23c05bfb28a5e60634d806323e31023375..01a567542c0620793b742c3e14eaf4eebbfeac97 100644 (file)
@@ -1,5 +1,5 @@
 /* Check section name for being that of a debug informatino section.
-   Copyright (C) 2002 Red Hat, Inc.
+   Copyright (C) 2002, 2014 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -40,5 +40,5 @@ ebl_debugscn_p (ebl, name)
      Ebl *ebl;
      const char *name;
 {
-  return ebl->debugscn_p (name);
+  return name != NULL && ebl->debugscn_p (name);
 }
index 633a8923f8529e891b187f6db7340df7073b8630..9ae24a9be4fa43d48f6533d9ca68ed9c00224bfe 100644 (file)
@@ -1,3 +1,7 @@
+2014-11-17  Mark Wielaard  <mjw@redhat.com>
+
+       * elf-knowledge.h (SECTION_STRIP_P): Check name is not NULL.
+
 2014-11-16  Mark Wielaard  <mjw@redhat.com>
 
        * elf_getshdrstrndx.c: Check there are section headers before
index 99fb910718ddd3adad6ba1de284f6efb752b51c2..24534b383036904e08bd61cdb04b805c56749448 100644 (file)
@@ -1,5 +1,5 @@
 /* Accumulation of various pieces of knowledge about ELF.
-   Copyright (C) 2000-2012 Red Hat, Inc.
+   Copyright (C) 2000-2012, 2014 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -41,7 +41,8 @@
    && (shdr)->sh_type != SHT_NOTE                                            \
    && (((shdr)->sh_type) != SHT_PROGBITS                                     \
        /* Never remove .gnu.warning.* sections.  */                          \
-       || (strncmp (name, ".gnu.warning.", sizeof ".gnu.warning." - 1) != 0   \
+       || (name != NULL                                                              \
+          && strncmp (name, ".gnu.warning.", sizeof ".gnu.warning." - 1) != 0\
           /* We remove .comment sections only if explicitly told to do so. */\
           && (remove_comment                                                 \
               || strcmp (name, ".comment") != 0))))
index 96f21fdc3915f7f22a0565e479a54723dc8b6906..727d1001ab2ffc88dae76ca3c3ed63d1bc6d2d4c 100644 (file)
@@ -1,3 +1,9 @@
+2014-11-17  Mark Wielaard  <mjw@redhat.com>
+
+       * elfcmp.c (main): Check section names are NULL before use.
+       * objdump.c (section_match): Likewise.
+       * size.c (show_sysv): Likewise.
+
 2014-11-17  Mark Wielaard  <mjw@redhat.com>
 
        * readelf.c (print_debug_frame_section): Warn if ptr_size is not 4
index 2d85f0b2e222b548263aa054386de87078082e54..c420019f58e5d4791612527e40ac30ba7687982f 100644 (file)
@@ -1,5 +1,5 @@
 /* Compare relevant content of two ELF files.
-   Copyright (C) 2005-2012 Red Hat, Inc.
+   Copyright (C) 2005-2012, 2014 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2005.
 
@@ -355,7 +355,8 @@ main (int argc, char *argv[])
                                              sym1->st_name);
              const char *name2 = elf_strptr (elf2, shdr2->sh_link,
                                              sym2->st_name);
-             if (unlikely (strcmp (name1, name2) != 0
+             if (unlikely (name1 == NULL || name2 == NULL
+                           || strcmp (name1, name2) != 0
                            || sym1->st_value != sym2->st_value
                            || (sym1->st_size != sym2->st_size
                                && sym1->st_shndx != SHN_UNDEF)
index ebad25d5228b0a8f7a9d036fc7c4ae71ed2961d2..5376447afca775f64cf2f657d01af3321b99ea4d 100644 (file)
@@ -1,5 +1,5 @@
 /* Print information from ELF file in human-readable form.
-   Copyright (C) 2005, 2006, 2007, 2009, 2011, 2012 Red Hat, Inc.
+   Copyright (C) 2005, 2006, 2007, 2009, 2011, 2012, 2014 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2005.
 
@@ -460,13 +460,13 @@ section_match (Elf *elf, uint32_t scnndx, GElf_Shdr *shdr, size_t shstrndx)
     return true;
 
   struct section_list *runp = section_list;
+  const char *name = elf_strptr (elf, shstrndx, shdr->sh_name);
 
   do
     {
       if (runp->is_name)
        {
-         if (strcmp (runp->name,
-                     elf_strptr (elf, shstrndx, shdr->sh_name)) == 0)
+         if (name && strcmp (runp->name, name) == 0)
            return true;
        }
       else
index 9db55c80d513fa1fa52ccad0b7fdbb65413bcc33..cb67999b4b9b4c3bf6fa5f9aca34575390564d28 100644 (file)
@@ -427,10 +427,9 @@ show_sysv (Elf *elf, const char *prefix, const char *fname,
        INTERNAL_ERROR (fullname);
 
       /* Ignore all sections which are not used at runtime.  */
-      if ((shdr->sh_flags & SHF_ALLOC) != 0)
-       maxlen = MAX (maxlen,
-                     (int) strlen (elf_strptr (elf, shstrndx,
-                                               shdr->sh_name)));
+      const char *name = elf_strptr (elf, shstrndx, shdr->sh_name);
+      if (name != NULL && (shdr->sh_flags & SHF_ALLOC) != 0)
+       maxlen = MAX (maxlen, (int) strlen (name));
     }
 
   fputs_unlocked (fname, stdout);