diff options
| author | Mark Wielaard <[email protected]> | 2017-03-27 17:01:57 +0200 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2017-04-04 00:03:27 +0200 |
| commit | a3bf8f0852d0f66911dcf879c5a1fcff3cb4cb46 (patch) | |
| tree | 27ee0205ab34f687d5bdde106e8a70217f1d67a3 /libelf/elf32_updatefile.c | |
| parent | 8dcc4bf791469a32c3a09ebcc23b309bf75c795f (diff) | |
libelf: Always update last_offset in updatefile and updatemmap.
When ELF section data was used, but not updated or marked as dirty and
there also existed non-dirty sections and some padding was needed between
the sections (possibly because of alignment) then elf_update might write
"fill" over some of the existing data. This happened because in that case
the last_position was not updated correctly.
Includes a new testcase fillfile that fails before this patch by showing
fill instead of the expected data in some section data. It succeeds with
this patch.
https://sourceware.org/bugzilla/show_bug.cgi?id=21199
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'libelf/elf32_updatefile.c')
| -rw-r--r-- | libelf/elf32_updatefile.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c index 8dd85d1a..7ac99510 100644 --- a/libelf/elf32_updatefile.c +++ b/libelf/elf32_updatefile.c @@ -343,9 +343,10 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum) { fill_mmap (dl->data.d.d_off, last_position, scn_start, shdr_start, shdr_end); - last_position = scn_start + dl->data.d.d_off; } + last_position = scn_start + dl->data.d.d_off; + if ((scn->flags | dl->flags | elf->flags) & ELF_F_DIRTY) { /* Let it go backward if the sections use a bogus @@ -353,8 +354,6 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum) user's section data with the latest one, rather than crashing. */ - last_position = scn_start + dl->data.d.d_off; - if (unlikely (change_bo)) { #if EV_NUM != 2 @@ -728,6 +727,8 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum) } } + last_offset = scn_start + dl->data.d.d_off; + if ((scn->flags | dl->flags | elf->flags) & ELF_F_DIRTY) { char tmpbuf[MAX_TMPBUF]; @@ -738,8 +739,6 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum) user's section data with the latest one, rather than crashing. */ - last_offset = scn_start + dl->data.d.d_off; - if (unlikely (change_bo)) { #if EV_NUM != 2 |
