]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: Only memcpy ehdr back when not already directly mmapped.
authorMark Wielaard <mjw@redhat.com>
Fri, 8 Nov 2013 18:28:16 +0000 (19:28 +0100)
committerMark Wielaard <mjw@redhat.com>
Mon, 11 Nov 2013 14:07:44 +0000 (15:07 +0100)
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 <mjw@redhat.com>
libelf/ChangeLog
libelf/elf32_updatefile.c

index a996ccf6fbfbabcc0ad9cef17776138a2019a71e..148c945347ac83f09bb6cfcf2ddb5cf12c6e8954 100644 (file)
@@ -1,3 +1,8 @@
+2013-11-08  Mark Wielaard  <mjw@redhat.com>
+
+       * elf32_updatefile.c (elfXX_updatemmap): Only memcpy ehdr when not
+       already directly mmapped.
+
 2013-11-05  Mark Wielaard  <mjw@redhat.com>
 
        * elf32_updatefile.c (elfXX_updatefile): Copy all section headers
index c4af9c0209b20be8b788659635e4862a670149aa..b39e28416778492230e79753fa10a58eb5d9fd00 100644 (file)
@@ -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)));