]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: Don't error out when sanity checking e_shoff if scncnt is zero.
authorMark Wielaard <mark@klomp.org>
Wed, 4 Oct 2017 18:52:53 +0000 (20:52 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 13 Oct 2017 14:22:06 +0000 (16:22 +0200)
We won't use the e_shoff value in that case because we will set
elf->state.elf[64|32].scns.cnt to zero to indicate not to read
any section header data from the file.

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

index 36b57dd1c827bd9e771a84d72d288cb51031a1f9..6aa1c6f55d2254a5e1327400c597a77ebd4d9660 100644 (file)
@@ -1,3 +1,8 @@
+2017-10-04  Mark Wielaard  <mark@klomp.org>
+
+       * elf_begin.c (file_read_elf): Skip sanity checking e_shoff if scncnt
+       is zero, we won't use it then.
+
 2017-10-04  Mark Wielaard  <mark@klomp.org>
 
        * libelfP.h: Add ELF_E_INVALID_ELF to error values enum.
index 554527837216d755726eb70521643d2d7d04f9b0..fb3a5b57f7c0346df243dfd9aac6b12a53ef9076 100644 (file)
@@ -373,7 +373,7 @@ file_read_elf (int fildes, void *map_address, unsigned char *e_ident,
              || (((uintptr_t) ((char *) ehdr + e_shoff)
                   & (__alignof__ (Elf32_Shdr) - 1)) == 0)))
        {
-         if (unlikely (e_shoff >= maxsize)
+         if (unlikely (scncnt > 0 && e_shoff >= maxsize)
              || unlikely (maxsize - e_shoff
                           < scncnt * sizeof (Elf32_Shdr)))
            {
@@ -475,7 +475,7 @@ file_read_elf (int fildes, void *map_address, unsigned char *e_ident,
              || (((uintptr_t) ((char *) ehdr + e_shoff)
                   & (__alignof__ (Elf64_Shdr) - 1)) == 0)))
        {
-         if (unlikely (e_shoff >= maxsize)
+         if (unlikely (scncnt > 0 && e_shoff >= maxsize)
              || unlikely (maxsize - e_shoff
                           < scncnt * sizeof (Elf64_Shdr)))
            goto free_and_out;