Date: Tue, 3 Jan 2017 15:57:47 +0000 (UTC) From: Ed Maste <emaste@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r311155 - stable/11/contrib/elftoolchain/elfcopy Message-ID: <201701031557.v03FvlGC063942@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: emaste Date: Tue Jan 3 15:57:47 2017 New Revision: 311155 URL: https://svnweb.freebsd.org/changeset/base/311155 Log: MFC r310634: elfcopy: fix PE object section name corruption and crash Fixed a bug that the PE object section names are generated incorrectly using the section name table found in the original input ELF object instead of the intermediate ELF object. Ticket: #541 Do not try to copy section content from a NULL d_buf when creating uninitialized data COFF section for PE object. Ticket: #540 Obtained from: ELF Tool Chain r3507, r3508 Modified: stable/11/contrib/elftoolchain/elfcopy/pe.c Directory Properties: stable/11/ (props changed) Modified: stable/11/contrib/elftoolchain/elfcopy/pe.c ============================================================================== --- stable/11/contrib/elftoolchain/elfcopy/pe.c Tue Jan 3 14:52:39 2017 (r311154) +++ stable/11/contrib/elftoolchain/elfcopy/pe.c Tue Jan 3 15:57:47 2017 (r311155) @@ -70,7 +70,7 @@ create_pe(struct elfcopy *ecp, int ifd, errx(EXIT_FAILURE, "gelf_getehdr() failed: %s", elf_errmsg(-1)); - if (elf_getshstrndx(ecp->ein, &indx) == 0) + if (elf_getshstrndx(e, &indx) == 0) errx(EXIT_FAILURE, "elf_getshstrndx() failed: %s", elf_errmsg(-1)); @@ -124,7 +124,7 @@ create_pe(struct elfcopy *ecp, int ifd, (void) elf_errno(); continue; } - if ((name = elf_strptr(ecp->ein, indx, sh.sh_name)) == + if ((name = elf_strptr(e, indx, sh.sh_name)) == NULL) { warnx("elf_strptr() failed: %s", elf_errmsg(-1)); (void) elf_errno(); @@ -210,12 +210,14 @@ create_pe(struct elfcopy *ecp, int ifd, } pb->pb_align = 1; pb->pb_off = 0; - pb->pb_size = roundup(sh.sh_size, poh.oh_filealign); - if ((pb->pb_buf = calloc(1, pb->pb_size)) == NULL) { - warn("calloc failed"); - continue; + if (sh.sh_type != SHT_NOBITS) { + pb->pb_size = roundup(sh.sh_size, poh.oh_filealign); + if ((pb->pb_buf = calloc(1, pb->pb_size)) == NULL) { + warn("calloc failed"); + continue; + } + memcpy(pb->pb_buf, d->d_buf, sh.sh_size); } - memcpy(pb->pb_buf, d->d_buf, sh.sh_size); } elferr = elf_errno(); if (elferr != 0)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201701031557.v03FvlGC063942>