From: Mark Wielaard Date: Fri, 8 Nov 2013 18:28:16 +0000 (+0100) Subject: libelf: Only memcpy ehdr back when not already directly mmapped. X-Git-Tag: elfutils-0.158~69 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3ba50403179131d6153923af71d00a909b62a147;p=thirdparty%2Felfutils.git libelf: Only memcpy ehdr back when not already directly mmapped. When the elf file is mmapped ehdr can still point to ehdr_mem if the address is unaligned. In such cases we do need to memcpy the ehdr back to the file. We shouldn't when ehdr already comes directly from the mmapped file, because that would cause an memcpy call with overlapping addresses (ehdr being copied directly over itself). Signed-off-by: Mark Wielaard --- diff --git a/libelf/ChangeLog b/libelf/ChangeLog index a996ccf6f..148c94534 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2013-11-08 Mark Wielaard + + * elf32_updatefile.c (elfXX_updatemmap): Only memcpy ehdr when not + already directly mmapped. + 2013-11-05 Mark Wielaard * elf32_updatefile.c (elfXX_updatefile): Copy all section headers diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c index c4af9c020..b39e28416 100644 --- a/libelf/elf32_updatefile.c +++ b/libelf/elf32_updatefile.c @@ -133,7 +133,7 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum) (*fctp) ((char *) elf->map_address + elf->start_offset, ehdr, sizeof (ElfW2(LIBELFBITS,Ehdr)), 1); } - else + else if (elf->map_address + elf->start_offset != ehdr) memcpy (elf->map_address + elf->start_offset, ehdr, sizeof (ElfW2(LIBELFBITS,Ehdr)));