From nobody Fri Dec 27 02:00:42 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 150207843699344.56158392550003; Sun, 6 Aug 2017 21:00:36 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 91C9C21D491A6; Sun, 6 Aug 2017 20:58:18 -0700 (PDT) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C654621E1DAFE for ; Sun, 6 Aug 2017 20:58:17 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP; 06 Aug 2017 21:00:33 -0700 Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.121]) by orsmga003.jf.intel.com with ESMTP; 06 Aug 2017 21:00:31 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,336,1498546800"; d="scan'208";a="1000787260" From: Yonghong Zhu To: edk2-devel@lists.01.org Date: Mon, 7 Aug 2017 12:00:29 +0800 Message-Id: <1502078429-13340-1-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 Subject: [edk2] [Patch] BaseTools: Fix Segmentation fault: 11 when build AppPkg with XCODE5 X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Andrew Fish , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" it is a bug in mtoc setting the size of the debug directory entry to the size of the .debug section, not the size of the EFI_IMAGE_DEBUG_DIRECTORY_ENTRY. It was causing a loop to iterate and get bogus EFI_IMAGE_DEBUG_DIRECTORY_ENTRY data and pass that to memset() and boom. Cc: Liming Gao Cc: Michael D Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Andrew Fish Reviewed-by: Liming Gao --- BaseTools/Source/C/GenFw/GenFw.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/C/GenFw/GenFw.c b/BaseTools/Source/C/GenFw/Ge= nFw.c index 246deb0..af60c92 100644 --- a/BaseTools/Source/C/GenFw/GenFw.c +++ b/BaseTools/Source/C/GenFw/GenFw.c @@ -2813,10 +2813,11 @@ Returns: // // Get Debug, Export and Resource EntryTable RVA address. // Resource Directory entry need to review. // Optional32Hdr =3D (EFI_IMAGE_OPTIONAL_HEADER32 *) ((UINT8*) FileHdr + si= zeof (EFI_IMAGE_FILE_HEADER)); + Optional64Hdr =3D (EFI_IMAGE_OPTIONAL_HEADER64 *) ((UINT8*) FileHdr + si= zeof (EFI_IMAGE_FILE_HEADER)); if (Optional32Hdr->Magic =3D=3D EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { SectionHeader =3D (EFI_IMAGE_SECTION_HEADER *) ((UINT8 *) Optional32Hd= r + FileHdr->SizeOfOptionalHeader); if (Optional32Hdr->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_EXP= ORT && \ Optional32Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT].Siz= e !=3D 0) { ExportDirectoryEntryRva =3D Optional32Hdr->DataDirectory[EFI_IMAGE_D= IRECTORY_ENTRY_EXPORT].VirtualAddress; @@ -2833,11 +2834,10 @@ Returns: Optional32Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].Size= =3D 0; Optional32Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].Virt= ualAddress =3D 0; } } } else { - Optional64Hdr =3D (EFI_IMAGE_OPTIONAL_HEADER64 *) ((UINT8*) FileHdr + = sizeof (EFI_IMAGE_FILE_HEADER)); SectionHeader =3D (EFI_IMAGE_SECTION_HEADER *) ((UINT8 *) Optional64Hd= r + FileHdr->SizeOfOptionalHeader); if (Optional64Hdr->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_EXP= ORT && \ Optional64Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT].Siz= e !=3D 0) { ExportDirectoryEntryRva =3D Optional64Hdr->DataDirectory[EFI_IMAGE_D= IRECTORY_ENTRY_EXPORT].VirtualAddress; } @@ -2907,10 +2907,20 @@ Returns: RsdsEntry->Unknown =3D 0; RsdsEntry->Unknown2 =3D 0; RsdsEntry->Unknown3 =3D 0; RsdsEntry->Unknown4 =3D 0; RsdsEntry->Unknown5 =3D 0; + } else if (RsdsEntry->Signature =3D=3D CODEVIEW_SIGNATURE_MTOC) { + // MTOC sets DebugDirectoryEntrySize to size of the .debug secti= on, so fix it. + if (!ZeroDebugFlag) { + if (Optional32Hdr->Magic =3D=3D EFI_IMAGE_NT_OPTIONAL_HDR32_MA= GIC) { + Optional32Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG= ].Size =3D sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); + } else { + Optional64Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG= ].Size =3D sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); + } + } + break; } } } } =20 --=20 2.6.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel