summaryrefslogtreecommitdiffstats
path: root/libelf/elf32_updatefile.c
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2013-11-08 19:28:16 +0100
committerMark Wielaard <[email protected]>2013-11-11 15:07:44 +0100
commit3ba50403179131d6153923af71d00a909b62a147 (patch)
treef77cf7108b35ceb22468df12bdfdc5d1d50b9ba6 /libelf/elf32_updatefile.c
parent03d76f4aec5e750b81198c7a24571e119e754b40 (diff)
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 <[email protected]>
Diffstat (limited to 'libelf/elf32_updatefile.c')
-rw-r--r--libelf/elf32_updatefile.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c
index c4af9c02..b39e2841 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)));