]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
elflint: Use shnum and shstrndx instead of ehdr field directly.
authorMark Wielaard <mark@klomp.org>
Wed, 12 Sep 2018 21:38:47 +0000 (23:38 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 13 Sep 2018 22:18:36 +0000 (00:18 +0200)
We already got the right shnum and shstrndx. But were still using
e_shnum in one check for ELFCLASS64 (it was correct for ELFCLASS32).
And when getting section names in check_symtab we still used
e_shstrndx in two places.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/elflint.c

index 79da69b01f4d0a6e93aaf08a8370cbce6b0115b9..a093a737a1e0b934de9490038268866440a18732 100644 (file)
@@ -1,3 +1,10 @@
+2018-09-13  Mark Wielaard  <mark@klomp.org>
+
+       * elflint.c (check_elf_header): Use shnum instead of e_shnum for all
+       checks.
+       (check_symtab): Use shstrndx instead of e_shstrndx to get section
+       names.
+
 2018-09-13  Mark Wielaard  <mark@klomp.org>
 
        * elfcmp.c (main): Get, check and shdrstrndx for section names.
index b49436ca95900c6070a415d7e581a54a6214470e..3d445954d666dbcff6d9440593e41f6c1d9f15c5 100644 (file)
@@ -541,7 +541,7 @@ invalid number of program header table entries\n"));
       if (ehdr->e_shentsize != 0 && ehdr->e_shentsize != sizeof (Elf64_Shdr))
        ERROR (gettext ("invalid section header size: %hd\n"),
               ehdr->e_shentsize);
-      else if (ehdr->e_shoff + ehdr->e_shnum * ehdr->e_shentsize > size)
+      else if (ehdr->e_shoff + shnum * ehdr->e_shentsize > size)
        ERROR (gettext ("invalid section header position or size\n"));
     }
 }
@@ -956,7 +956,7 @@ section [%2d] '%s': symbol %zu: non-local section symbol\n"),
                      destshdr = gelf_getshdr (gscn, &destshdr_mem);
                      assert (destshdr != NULL);
                      const char *sname = elf_strptr (ebl->elf,
-                                                     ehdr->e_shstrndx,
+                                                     shstrndx,
                                                      destshdr->sh_name);
                      if (sname != NULL)
                        {
@@ -977,7 +977,7 @@ section [%2d] '%s': symbol %zu: non-local section symbol\n"),
 
              const char *sname = ((destshdr == NULL || xndx == SHN_UNDEF)
                                   ? NULL
-                                  : elf_strptr (ebl->elf, ehdr->e_shstrndx,
+                                  : elf_strptr (ebl->elf, shstrndx,
                                                 destshdr->sh_name));
              if (sname == NULL)
                {