]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: Write all section headers if elf flags contains ELF_F_DIRTY.
authorMark Wielaard <mjw@redhat.com>
Tue, 5 Nov 2013 15:27:32 +0000 (16:27 +0100)
committerMark Wielaard <mjw@redhat.com>
Tue, 5 Nov 2013 21:17:51 +0000 (22:17 +0100)
When ehdr e_shoff changes, elf flags is set dirty. This indicates that
the section header moved because sections were added/removed or changed
in size.

Reported-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
libelf/ChangeLog
libelf/elf32_updatefile.c

index c2c5fc420d47c7bc6bf3032bc8dfcd9eba308797..a996ccf6fbfbabcc0ad9cef17776138a2019a71e 100644 (file)
@@ -1,3 +1,8 @@
+2013-11-05  Mark Wielaard  <mjw@redhat.com>
+
+       * elf32_updatefile.c (elfXX_updatefile): Copy all section headers
+       if elf->flags dirty.
+
 2013-11-01  Michael Forney  <mforney@mforney.org>
 
        * Makefile.am: Use READELF.
index 296b1ac9d28c998f7fe1e99fd62b3650456a4c12..c4af9c0209b20be8b788659635e4862a670149aa 100644 (file)
@@ -633,7 +633,8 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum)
 #endif
 
       ElfW2(LIBELFBITS,Shdr) *shdr_data;
-      if (change_bo || elf->state.ELFW(elf,LIBELFBITS).shdr == NULL)
+      if (change_bo || elf->state.ELFW(elf,LIBELFBITS).shdr == NULL
+         || (elf->flags & ELF_F_DIRTY))
        shdr_data = (ElfW2(LIBELFBITS,Shdr) *)
          alloca (shnum * sizeof (ElfW2(LIBELFBITS,Shdr)));
       else
@@ -764,7 +765,8 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum)
            (*shdr_fctp) (&shdr_data[scn->index],
                          scn->shdr.ELFW(e,LIBELFBITS),
                          sizeof (ElfW2(LIBELFBITS,Shdr)), 1);
-         else if (elf->state.ELFW(elf,LIBELFBITS).shdr == NULL)
+         else if (elf->state.ELFW(elf,LIBELFBITS).shdr == NULL
+                  || (elf->flags & ELF_F_DIRTY))
            memcpy (&shdr_data[scn->index], scn->shdr.ELFW(e,LIBELFBITS),
                    sizeof (ElfW2(LIBELFBITS,Shdr)));