Reviewed-by: Liming Gao <[email protected]> >-----Original Message----- >From: Zhu, Yonghong >Sent: Monday, August 07, 2017 12:00 PM >To: [email protected] >Cc: Gao, Liming <[email protected]>; Kinney, Michael D ><[email protected]>; Andrew Fish <[email protected]> >Subject: [Patch] BaseTools: Fix Segmentation fault: 11 when build AppPkg >with XCODE5 > >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 <[email protected]> >Cc: Michael D Kinney <[email protected]> >Contributed-under: TianoCore Contribution Agreement 1.0 >Signed-off-by: Andrew Fish <[email protected]> >--- > 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/GenFw.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 = (EFI_IMAGE_OPTIONAL_HEADER32 *) ((UINT8*) FileHdr + >sizeof (EFI_IMAGE_FILE_HEADER)); >+ Optional64Hdr = (EFI_IMAGE_OPTIONAL_HEADER64 *) ((UINT8*) FileHdr + >sizeof (EFI_IMAGE_FILE_HEADER)); > if (Optional32Hdr->Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { > SectionHeader = (EFI_IMAGE_SECTION_HEADER *) ((UINT8 *) >Optional32Hdr + FileHdr->SizeOfOptionalHeader); > if (Optional32Hdr->NumberOfRvaAndSizes > >EFI_IMAGE_DIRECTORY_ENTRY_EXPORT && \ > Optional32Hdr- >>DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT].Size != 0) { > ExportDirectoryEntryRva = Optional32Hdr- >>DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; >@@ -2833,11 +2834,10 @@ Returns: > Optional32Hdr- >>DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].Size = 0; > Optional32Hdr- >>DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress = 0; > } > } > } else { >- Optional64Hdr = (EFI_IMAGE_OPTIONAL_HEADER64 *) ((UINT8*) FileHdr + >sizeof (EFI_IMAGE_FILE_HEADER)); > SectionHeader = (EFI_IMAGE_SECTION_HEADER *) ((UINT8 *) >Optional64Hdr + FileHdr->SizeOfOptionalHeader); > if (Optional64Hdr->NumberOfRvaAndSizes > >EFI_IMAGE_DIRECTORY_ENTRY_EXPORT && \ > Optional64Hdr- >>DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT].Size != 0) { > ExportDirectoryEntryRva = Optional64Hdr- >>DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; > } >@@ -2907,10 +2907,20 @@ Returns: > RsdsEntry->Unknown = 0; > RsdsEntry->Unknown2 = 0; > RsdsEntry->Unknown3 = 0; > RsdsEntry->Unknown4 = 0; > RsdsEntry->Unknown5 = 0; >+ } else if (RsdsEntry->Signature == CODEVIEW_SIGNATURE_MTOC) { >+ // MTOC sets DebugDirectoryEntrySize to size of the .debug section, >so >fix it. >+ if (!ZeroDebugFlag) { >+ if (Optional32Hdr->Magic == >EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { >+ Optional32Hdr- >>DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].Size = sizeof >(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); >+ } else { >+ Optional64Hdr- >>DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].Size = sizeof >(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); >+ } >+ } >+ break; > } > } > } > } > >-- >2.6.1.windows.1
_______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

