From 57dfc48f933ce50c2d269e66eec7bab0c66938d6 Mon Sep 17 00:00:00 2001 From: eric_tian Date: Mon, 2 Feb 2009 08:01:35 +0000 Subject: [PATCH] enhance the condition branch to handle Unix style file path. and avoid array overflow git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7394 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Core/Dxe/Image/Image.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 36893d9650..1ee65ae024 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -477,19 +477,22 @@ CoreLoadPeImage ( // - // Print Module Name by Pdb file path + // Print Module Name by Pdb file path. + // Windows and Unix style file path are all trimmed correctly. // if (Image->ImageContext.PdbPointer != NULL) { StartIndex = 0; for (Index = 0; Image->ImageContext.PdbPointer[Index] != 0; Index++) { - if (Image->ImageContext.PdbPointer[Index] == '\\') { + if ((Image->ImageContext.PdbPointer[Index] == '\\') || (Image->ImageContext.PdbPointer[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~255. + // If the length is bigger than 255, trim the redudant characters to avoid overflow in array boundary. // - for (Index = 0; Index < sizeof (EfiFileName); Index++) { + for (Index = 0; Index < sizeof (EfiFileName) - 4; Index++) { EfiFileName[Index] = Image->ImageContext.PdbPointer[Index + StartIndex]; if (EfiFileName[Index] == 0) { EfiFileName[Index] = '.'; @@ -502,6 +505,10 @@ CoreLoadPeImage ( break; } } + + if (Index == sizeof (EfiFileName) - 4) { + EfiFileName[Index] = 0; + } DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex])); } DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n")); -- 2.39.2