From 77a750a550e60b69bf1b43c7413ab15a0cad09d9 Mon Sep 17 00:00:00 2001 From: lgao4 Date: Wed, 29 Feb 2012 04:56:53 +0000 Subject: [PATCH] Fix the issue in PeiCore to support PDB file path without '\' or '.' character. Signed-off-by: lgao4 Reviewed-by: rsun3 git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13069 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Core/Pei/Image/Image.c | 36 +++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/MdeModulePkg/Core/Pei/Image/Image.c b/MdeModulePkg/Core/Pei/Image/Image.c index 843e020142..41069e7a31 100644 --- a/MdeModulePkg/Core/Pei/Image/Image.c +++ b/MdeModulePkg/Core/Pei/Image/Image.c @@ -549,9 +549,9 @@ PeiLoadImageLoadImage ( DEBUG_CODE_BEGIN (); CHAR8 *AsciiString; - CHAR8 AsciiBuffer[512]; + CHAR8 EfiFileName[512]; INT32 Index; - INT32 Index1; + INT32 StartIndex; // // Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi @@ -571,19 +571,37 @@ PeiLoadImageLoadImage ( AsciiString = PeCoffLoaderGetPdbPointer (Pe32Data); if (AsciiString != NULL) { - for (Index = (INT32) AsciiStrLen (AsciiString) - 1; Index >= 0; Index --) { + StartIndex = 0; + for (Index = 0; AsciiString[Index] != 0; Index++) { if (AsciiString[Index] == '\\' || AsciiString[Index] == '/') { + StartIndex = Index + 1; + } + } + + // + // Copy the PDB file name to our temporary string, and replace .pdb with .efi + // The PDB file name is limited in the range of 0~511. + // If the length is bigger than 511, trim the redudant characters to avoid overflow in array boundary. + // + for (Index = 0; Index < sizeof (EfiFileName) - 4; Index++) { + EfiFileName[Index] = AsciiString[Index + StartIndex]; + if (EfiFileName[Index] == 0) { + EfiFileName[Index] = '.'; + } + if (EfiFileName[Index] == '.') { + EfiFileName[Index + 1] = 'e'; + EfiFileName[Index + 2] = 'f'; + EfiFileName[Index + 3] = 'i'; + EfiFileName[Index + 4] = 0; break; } } - if (Index != 0) { - for (Index1 = 0; AsciiString[Index + 1 + Index1] != '.'; Index1 ++) { - AsciiBuffer [Index1] = AsciiString[Index + 1 + Index1]; - } - AsciiBuffer [Index1] = '\0'; - DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a.efi", AsciiBuffer)); + if (Index == sizeof (EfiFileName) - 4) { + EfiFileName[Index] = 0; } + + DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a", EfiFileName)); } DEBUG_CODE_END ();