summaryrefslogtreecommitdiff
path: root/libelf/elf32_getshdr.c
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2012-07-18 13:14:30 +0200
committerMark Wielaard <mjw@redhat.com>2012-07-24 11:41:01 +0200
commit030f626f41b5d1d563c357743cfec492d4fa69a5 (patch)
treed8454ca3cf576a8bc824957e1642ce73c4709a57 /libelf/elf32_getshdr.c
parentadcd1dd5729fdee3e85253b541767cc28809e4d9 (diff)
downloadelfutils-030f626f41b5d1d563c357743cfec492d4fa69a5.tar.gz
elf_getshdr should work for elf->flags & ELF_F_MALLOCED.
Reported-by: Nick Alcock <nix@esperi.org.uk> Signed-off-by: Mark Wielaard <mjw@redhat.com>
Diffstat (limited to 'libelf/elf32_getshdr.c')
-rw-r--r--libelf/elf32_getshdr.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/libelf/elf32_getshdr.c b/libelf/elf32_getshdr.c
index f0319cbb..bd9340dd 100644
--- a/libelf/elf32_getshdr.c
+++ b/libelf/elf32_getshdr.c
@@ -1,5 +1,5 @@
/* Return section header.
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2007, 2009 Red Hat, Inc.
+ Copyright (C) 1998-2002, 2005, 2007, 2009, 2012 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 1998.
@@ -80,11 +80,14 @@ load_shdr_wrlock (Elf_Scn *scn)
ElfW2(LIBELFBITS,Shdr) *notcvt;
/* All the data is already mapped. If we could use it
- directly this would already have happened. */
+ directly this would already have happened. Unless
+ we allocated the memory ourselves and the ELF_F_MALLOCED
+ flag is set. */
void *file_shdr = ((char *) elf->map_address
+ elf->start_offset + ehdr->e_shoff);
- assert (ehdr->e_ident[EI_DATA] != MY_ELFDATA
+ assert ((elf->flags & ELF_F_MALLOCED)
+ || ehdr->e_ident[EI_DATA] != MY_ELFDATA
|| (! ALLOW_UNALIGNED
&& ((uintptr_t) file_shdr
& (__alignof__ (ElfW2(LIBELFBITS,Shdr)) - 1)) != 0));
@@ -92,7 +95,7 @@ load_shdr_wrlock (Elf_Scn *scn)
/* Now copy the data and at the same time convert the byte order. */
if (ehdr->e_ident[EI_DATA] == MY_ELFDATA)
{
- assert (! ALLOW_UNALIGNED);
+ assert ((elf->flags & ELF_F_MALLOCED) || ! ALLOW_UNALIGNED);
memcpy (shdr, file_shdr, size);
}
else