There is an assert in load_shdr_wrlock for the case the map_address is
not NULL. It shows how we could arrive in that state. One condition
might be because ALLOWED_UNALIGNED isn't set, but the the shdrs table
pointer was unaligned. That has been changed to the shdrs table
pointer just not being properly aligned. Otherwise elf_begin function
file_read_elf would have set it already.

If the pointer is unaligned and the endianess is different, we make a
copy of te shdrs table first to convert it, using code that assumes
properly aligned types. This copy was skipped when ALLOW_UNALIGNED was
set. That situation, unaligned Elf structures and different
endianness, is very rare, so just drop the ALLOW_UNALIGNED condition.

        * libelf/elf32_getshdr.c (load_shdr_wrlock): Drop
        ALLOW_UNALIGNED condition.

Signed-off-by: Mark Wielaard <[email protected]>
---
 libelf/elf32_getshdr.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/libelf/elf32_getshdr.c b/libelf/elf32_getshdr.c
index cb88267ebbe8..9df6717e978c 100644
--- a/libelf/elf32_getshdr.c
+++ b/libelf/elf32_getshdr.c
@@ -99,19 +99,16 @@ load_shdr_wrlock (Elf_Scn *scn)
       assert ((elf->flags & (ELF_F_MALLOCED | ELF_F_PARENT_MALLOCED))
              || ehdr->e_ident[EI_DATA] != MY_ELFDATA
              || elf->cmd == ELF_C_READ_MMAP
-             || (! ALLOW_UNALIGNED
-                 && ((uintptr_t) file_shdr
-                     & (__alignof__ (ElfW2(LIBELFBITS,Shdr)) - 1)) != 0));
+             || ((uintptr_t) file_shdr
+                 & (__alignof__ (ElfW2(LIBELFBITS,Shdr)) - 1)) != 0);
 
       /* Now copy the data and at the same time convert the byte order.  */
       if (ehdr->e_ident[EI_DATA] == MY_ELFDATA)
        memcpy (shdr, file_shdr, size);
       else
        {
-         bool copy = ! (ALLOW_UNALIGNED
-                        || ((uintptr_t) file_shdr
-                            & (__alignof__ (ElfW2(LIBELFBITS,Shdr)) - 1))
-                            == 0);
+         bool copy = ((uintptr_t) file_shdr
+                      & (__alignof__ (ElfW2(LIBELFBITS,Shdr)) - 1)) != 0;
          if (! copy)
            notcvt = (ElfW2(LIBELFBITS,Shdr) *)
              ((char *) elf->map_address
-- 
2.56.1

Reply via email to