From 3adda3ce2a83e2733aa0c84da9bb7949413d02fd Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 29 Sep 2015 17:04:11 +0200 Subject: 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 --- libelf/ChangeLog | 5 +++++ libelf/elf32_updatenull.c | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'libelf') 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 + + * elf32_updatenull.c (default_ehdr): Set e_version when EV_NONE. + (updatenull_wrlock): Always set e_shentsize. + 2015-09-23 Mark Wielaard * 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); -- cgit v1.2.3