summaryrefslogtreecommitdiffstats
path: root/libelf
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2015-09-29 17:04:11 +0200
committerMark Wielaard <mjw@redhat.com>2015-10-05 21:50:51 +0200
commit3adda3ce2a83e2733aa0c84da9bb7949413d02fd (patch)
tree058bc279d05d01de93eac34fdc7705d720f865e2 /libelf
parenta3a76e361527b057fc4cf8a8a8ce97a33dd59198 (diff)
downloadandroid_external_elfutils-3adda3ce2a83e2733aa0c84da9bb7949413d02fd.tar.gz
android_external_elfutils-3adda3ce2a83e2733aa0c84da9bb7949413d02fd.tar.bz2
android_external_elfutils-3adda3ce2a83e2733aa0c84da9bb7949413d02fd.zip
libelf: Always update e_version and e_shentsize in elf_update.
When e_version is EV_NONE we should set it to EV_CURRENT like we do for the EI_VERSION and like we set EI_DATA to the correct byte order when set to ELFDATANONE. Likewise we should always set e_shentsize like we do for e_phentsize, not just when ELF_F_LAYOUT isn't set. Add a new elfshphehdr testcase to check the above. Signed-off-by: Mark Wielaard <mjw@redhat.com>
Diffstat (limited to 'libelf')
-rw-r--r--libelf/ChangeLog5
-rw-r--r--libelf/elf32_updatenull.c13
2 files changed, 13 insertions, 5 deletions
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 1916877c..0609b37d 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,8 @@
+2015-09-29 Mark Wielaard <mjw@redhat.com>
+
+ * elf32_updatenull.c (default_ehdr): Set e_version when EV_NONE.
+ (updatenull_wrlock): Always set e_shentsize.
+
2015-09-23 Mark Wielaard <mjw@redhat.com>
* elf32_getehdr.c (getehdr_wrlock): Mark as internal_function.
diff --git a/libelf/elf32_updatenull.c b/libelf/elf32_updatenull.c
index c59ffcbd..d3754d32 100644
--- a/libelf/elf32_updatenull.c
+++ b/libelf/elf32_updatenull.c
@@ -84,8 +84,12 @@ ELFW(default_ehdr,LIBELFBITS) (Elf *elf, ElfW2(LIBELFBITS,Ehdr) *ehdr,
update_if_changed (ehdr->e_ident[EI_VERSION], EV_CURRENT,
elf->state.ELFW(elf,LIBELFBITS).ehdr_flags);
- if (unlikely (ehdr->e_version == EV_NONE)
- || unlikely (ehdr->e_version >= EV_NUM))
+ if (unlikely (ehdr->e_version == EV_NONE))
+ {
+ ehdr->e_version = EV_CURRENT;
+ elf->state.ELFW(elf,LIBELFBITS).ehdr_flags |= ELF_F_DIRTY;
+ }
+ else if (unlikely (ehdr->e_version >= EV_NUM))
{
__libelf_seterrno (ELF_E_UNKNOWN_VERSION);
return 1;
@@ -394,6 +398,8 @@ __elfw2(LIBELFBITS,updatenull_wrlock) (Elf *elf, int *change_bop, size_t shnum)
while ((list = list->next) != NULL);
/* Store section information. */
+ update_if_changed (ehdr->e_shentsize,
+ elf_typesize (LIBELFBITS, ELF_T_SHDR, 1), ehdr_flags);
if (elf->flags & ELF_F_LAYOUT)
{
/* The user is supposed to fill out e_shoff. Use it and
@@ -414,9 +420,6 @@ __elfw2(LIBELFBITS,updatenull_wrlock) (Elf *elf, int *change_bop, size_t shnum)
size = (size + SHDR_ALIGN - 1) & ~(SHDR_ALIGN - 1);
update_if_changed (ehdr->e_shoff, (GElf_Word) size, elf->flags);
- update_if_changed (ehdr->e_shentsize,
- elf_typesize (LIBELFBITS, ELF_T_SHDR, 1),
- ehdr_flags);
/* Account for the section header size. */
size += elf_typesize (LIBELFBITS, ELF_T_SHDR, shnum);