diff options
| author | Ed Maste <emaste@FreeBSD.org> | 2019-01-10 14:18:11 +0000 |
|---|---|---|
| committer | Ed Maste <emaste@FreeBSD.org> | 2019-01-10 14:18:11 +0000 |
| commit | 2b92b30119ed91ed88f102ba9ecc40cd1c046a65 (patch) | |
| tree | 5cde2d0340810533c039044df9508aee4fd482b3 /libelf/elf_update.c | |
| parent | 87ec209e33f42bd708452228ae84ded370b70163 (diff) | |
Diffstat (limited to 'libelf/elf_update.c')
| -rw-r--r-- | libelf/elf_update.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/libelf/elf_update.c b/libelf/elf_update.c index 6cc109daafcc..25fa98d0bb12 100644 --- a/libelf/elf_update.c +++ b/libelf/elf_update.c @@ -41,7 +41,7 @@ #include <sys/mman.h> #endif -ELFTC_VCSID("$Id: elf_update.c 3190 2015-05-04 15:23:08Z jkoshy $"); +ELFTC_VCSID("$Id: elf_update.c 3632 2018-10-10 21:12:43Z jkoshy $"); /* * Layout strategy: @@ -712,8 +712,8 @@ _libelf_resync_elf(Elf *e, struct _Elf_Extent_List *extents) static off_t _libelf_write_scn(Elf *e, unsigned char *nf, struct _Elf_Extent *ex) { - int ec; off_t rc; + int ec, em; Elf_Scn *s; int elftype; Elf_Data *d, dst; @@ -747,6 +747,9 @@ _libelf_write_scn(Elf *e, unsigned char *nf, struct _Elf_Extent *ex) sh_off = s->s_offset; assert(sh_off % _libelf_falign(elftype, ec) == 0); + em = _libelf_elfmachine(e); + assert(em >= EM_NONE && em < EM__LAST__); + /* * If the section has a `rawdata' descriptor, and the section * contents have not been modified, use its contents directly. @@ -817,8 +820,8 @@ _libelf_write_scn(Elf *e, unsigned char *nf, struct _Elf_Extent *ex) dst.d_buf = nf + rc; dst.d_size = fsz; - if (_libelf_xlate(&dst, d, e->e_byteorder, ec, ELF_TOFILE) == - NULL) + if (_libelf_xlate(&dst, d, e->e_byteorder, ec, em, ELF_TOFILE) + == NULL) return ((off_t) -1); rc += (off_t) fsz; @@ -834,7 +837,7 @@ _libelf_write_scn(Elf *e, unsigned char *nf, struct _Elf_Extent *ex) static off_t _libelf_write_ehdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex) { - int ec; + int ec, em; void *ehdr; size_t fsz, msz; Elf_Data dst, src; @@ -850,6 +853,8 @@ _libelf_write_ehdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex) fsz = _libelf_fsize(ELF_T_EHDR, ec, e->e_version, (size_t) 1); msz = _libelf_msize(ELF_T_EHDR, ec, e->e_version); + em = _libelf_elfmachine(e); + (void) memset(&dst, 0, sizeof(dst)); (void) memset(&src, 0, sizeof(src)); @@ -861,7 +866,7 @@ _libelf_write_ehdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex) dst.d_buf = nf; dst.d_size = fsz; - if (_libelf_xlate(&dst, &src, e->e_byteorder, ec, ELF_TOFILE) == + if (_libelf_xlate(&dst, &src, e->e_byteorder, ec, em, ELF_TOFILE) == NULL) return ((off_t) -1); @@ -875,7 +880,7 @@ _libelf_write_ehdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex) static off_t _libelf_write_phdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex) { - int ec; + int ec, em; void *ehdr; Elf32_Ehdr *eh32; Elf64_Ehdr *eh64; @@ -899,6 +904,8 @@ _libelf_write_phdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex) phoff = eh64->e_phoff; } + em = _libelf_elfmachine(e); + assert(phoff > 0); assert(ex->ex_start == phoff); assert(phoff % _libelf_falign(ELF_T_PHDR, ec) == 0); @@ -918,7 +925,7 @@ _libelf_write_phdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex) dst.d_size = fsz; dst.d_buf = nf + ex->ex_start; - if (_libelf_xlate(&dst, &src, e->e_byteorder, ec, ELF_TOFILE) == + if (_libelf_xlate(&dst, &src, e->e_byteorder, ec, em, ELF_TOFILE) == NULL) return ((off_t) -1); @@ -932,7 +939,7 @@ _libelf_write_phdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex) static off_t _libelf_write_shdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex) { - int ec; + int ec, em; void *ehdr; Elf_Scn *scn; uint64_t shoff; @@ -955,6 +962,8 @@ _libelf_write_shdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex) shoff = eh64->e_shoff; } + em = _libelf_elfmachine(e); + assert(nscn > 0); assert(shoff % _libelf_falign(ELF_T_SHDR, ec) == 0); assert(ex->ex_start == shoff); @@ -977,8 +986,8 @@ _libelf_write_shdr(Elf *e, unsigned char *nf, struct _Elf_Extent *ex) dst.d_size = fsz; dst.d_buf = nf + ex->ex_start + scn->s_ndx * fsz; - if (_libelf_xlate(&dst, &src, e->e_byteorder, ec, - ELF_TOFILE) == NULL) + if (_libelf_xlate(&dst, &src, e->e_byteorder, ec, em, + ELF_TOFILE) == NULL) return ((off_t) -1); } |
