diff options
| author | Mark Wielaard <mark@klomp.org> | 2019-05-12 00:37:45 +0200 |
|---|---|---|
| committer | Mark Wielaard <mark@klomp.org> | 2019-05-16 17:57:41 +0200 |
| commit | d7193bd7c9dc2a979352eee7fc446dacd3e97779 (patch) | |
| tree | 3fbc54875c7c3a378d096a2689f4a19436e0bd2d /libelf | |
| parent | a117891a00507d188fdab415bd25554ace9ed7ba (diff) | |
| download | platform_external_elfutils-d7193bd7c9dc2a979352eee7fc446dacd3e97779.tar.gz platform_external_elfutils-d7193bd7c9dc2a979352eee7fc446dacd3e97779.tar.bz2 platform_external_elfutils-d7193bd7c9dc2a979352eee7fc446dacd3e97779.zip | |
libelf: Mark shdr_flags dirty if offset or size changes during update.
We forgot to mark the shdr_flags dirty when only the sh_size or
sh_offset changed during elf_update (). This meant that if there were
no other shdr changes we only wrote out the section data, but didn't
write out the shdr table to the file.
Add a testcase that puts some sections in the reverse order and then
writes out the resulting file again without doing any other
updates. This would show the issue after write out of the
(re-reversed) ELF file (the .shstrtab section offset would be wrong
causing all section names to be garbage). Also run a self test.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libelf')
| -rw-r--r-- | libelf/ChangeLog | 5 | ||||
| -rw-r--r-- | libelf/elf32_updatenull.c | 5 |
2 files changed, 9 insertions, 1 deletions
diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 924ff591..82e18ebc 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2019-05-12 Mark Wielaard <mark@klomp.org> + + * elf32_updatenull.c (updatenull_wrlock): Mark shdr_flags dirty if + either offset or size changed. + 2019-05-01 Mark Wielaard <mark@klomp.org> * gelf_getnote.c (gelf_getnote): Check n_namesz doesn't overflow diff --git a/libelf/elf32_updatenull.c b/libelf/elf32_updatenull.c index 2ce6a597..303055a0 100644 --- a/libelf/elf32_updatenull.c +++ b/libelf/elf32_updatenull.c @@ -366,12 +366,15 @@ __elfw2(LIBELFBITS,updatenull_wrlock) (Elf *elf, int *change_bop, size_t shnum) } /* See whether the section size is correct. */ + int size_changed = 0; update_if_changed (shdr->sh_size, (GElf_Word) offset, - changed); + size_changed); + changed |= size_changed; if (shdr->sh_type != SHT_NOBITS) size += offset; + scn->shdr_flags |= (offset_changed | size_changed); scn->flags |= changed; } |
