summaryrefslogtreecommitdiffstats
path: root/libelf/elf32_updatefile.c
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2018-09-12 23:38:28 +0200
committerMark Wielaard <[email protected]>2018-09-13 14:30:30 +0200
commit34534cc1740b198b8999dcf97222940a130905ce (patch)
treeef28e793954155f6a5de14e4e49b0dd30b3c8226 /libelf/elf32_updatefile.c
parentbe4ea50a689dcfdb46079f8f5ce616107a77cdc4 (diff)
libelf: Fix shnum and section zero handling.
For ELF files with more than SHN_LOWRESERVE sections we always need section zero to store the section number (it doesn't just fit in the Ehdr e_shnum field). Make sure to create it if it doesn't exist yet in elf_getscn. Also fix handling on shnum in updatefile for the mmap case (we already got this correct for the non-mmap case). This adds a new test run-copymany-sections.sh which is like run-copyadd-sections.sh but tries to add two times 65535 sections. It makes sure libelf can copy the whole file and elfcmp checks they are the same. It doesn't use mmap for addsections since that doesn't work yet. ELF_C_RDWR_MMAP needs mremap which will fail since it needs too much space and the original mmap cannot move. Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'libelf/elf32_updatefile.c')
-rw-r--r--libelf/elf32_updatefile.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c
index 545ce083..f2e9a288 100644
--- a/libelf/elf32_updatefile.c
+++ b/libelf/elf32_updatefile.c
@@ -236,7 +236,7 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
}
char *const shdr_start = ((char *) elf->map_address + elf->start_offset
+ ehdr->e_shoff);
- char *const shdr_end = shdr_start + ehdr->e_shnum * ehdr->e_shentsize;
+ char *const shdr_end = shdr_start + shnum * ehdr->e_shentsize;
#if EV_NUM != 2
xfct_t shdr_fctp = __elf_xfctstom[__libelf_version - 1][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_SHDR];