From owner-svn-src-all@freebsd.org Tue Dec 27 17:31:08 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B0DB8C92B90; Tue, 27 Dec 2016 17:31:08 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 671C0179E; Tue, 27 Dec 2016 17:31:08 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uBRHV7BO004205; Tue, 27 Dec 2016 17:31:07 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uBRHV7Ul004204; Tue, 27 Dec 2016 17:31:07 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201612271731.uBRHV7Ul004204@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Tue, 27 Dec 2016 17:31:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r310634 - head/contrib/elftoolchain/elfcopy X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Dec 2016 17:31:08 -0000 Author: emaste Date: Tue Dec 27 17:31:07 2016 New Revision: 310634 URL: https://svnweb.freebsd.org/changeset/base/310634 Log: 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 MFC after: 1 week Modified: head/contrib/elftoolchain/elfcopy/pe.c Modified: head/contrib/elftoolchain/elfcopy/pe.c ============================================================================== --- head/contrib/elftoolchain/elfcopy/pe.c Tue Dec 27 17:13:31 2016 (r310633) +++ head/contrib/elftoolchain/elfcopy/pe.c Tue Dec 27 17:31:07 2016 (r310634) @@ -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)