]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
nm: First call elf_getdata, then allocate memory.
authorMark Wielaard <mjw@redhat.com>
Sat, 27 Jun 2015 20:07:01 +0000 (22:07 +0200)
committerMark Wielaard <mjw@redhat.com>
Sat, 27 Jun 2015 20:07:01 +0000 (22:07 +0200)
This catches bogus data early before we might try to allocate giant
amounts of memory.

Reported-by: Hanno Böck <hanno@hboeck.de>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
src/ChangeLog
src/nm.c

index 7d5e001b0e5399677f6276bdcf0c7cd07724bc07..50223a4fc911f6cb22c255a55f692bc20e7cdec3 100644 (file)
@@ -1,3 +1,7 @@
+2015-06-27  Mark Wielaard  <mjw@redhat.com>
+
+       * nm.c (show_symbols): First call elf_getdata, then allocate memory.
+
 2015-06-18  Mark Wielaard  <mjw@redhat.com>
 
        * findtextrel.c (process_file): Free segments after use.
index 7339506975ff253dcce80de2f93da03c1c8db098..15d9da4abe5dfe76663adc0fb45ce72749fba1a8 100644 (file)
--- a/src/nm.c
+++ b/src/nm.c
@@ -1200,6 +1200,12 @@ show_symbols (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, Elf_Scn *xndxscn,
        }
     }
 
+  /* Get the data of the section.  */
+  Elf_Data *data = elf_getdata (scn, NULL);
+  Elf_Data *xndxdata = elf_getdata (xndxscn, NULL);
+  if (data == NULL || (xndxscn != NULL && xndxdata == NULL))
+    INTERNAL_ERROR (fullname);
+
   /* Allocate the memory.
 
      XXX We can use a dirty trick here.  Since GElf_Sym == Elf64_Sym we
@@ -1211,12 +1217,6 @@ show_symbols (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, Elf_Scn *xndxscn,
   else
     sym_mem = (GElf_SymX *) xmalloc (nentries * sizeof (GElf_SymX));
 
-  /* Get the data of the section.  */
-  Elf_Data *data = elf_getdata (scn, NULL);
-  Elf_Data *xndxdata = elf_getdata (xndxscn, NULL);
-  if (data == NULL || (xndxscn != NULL && xndxdata == NULL))
-    INTERNAL_ERROR (fullname);
-
   /* Iterate over all symbols.  */
 #ifdef USE_DEMANGLE
   size_t demangle_buffer_len = 0;