summaryrefslogtreecommitdiff
path: root/MdePkg
diff options
context:
space:
mode:
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>2009-04-23 12:14:55 +0000
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>2009-04-23 12:14:55 +0000
commit50cd68dfb5de38ab01c132cd0e4d866690527e77 (patch)
tree91fa227cf481d70c0090d5b84492700236539b19 /MdePkg
parent55a1bb43aa37fc948911197a99e23199fcc58b72 (diff)
downloadedk2-platforms-50cd68dfb5de38ab01c132cd0e4d866690527e77.tar.xz
Add check for the validity of resource directory address.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8164 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg')
-rw-r--r--MdePkg/Library/BasePeCoffLib/BasePeCoff.c64
1 files changed, 32 insertions, 32 deletions
diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
index 3ecc015eac..e3a7b5387b 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
@@ -67,7 +67,7 @@ PeCoffLoaderGetPeHeader (
UINT16 Magic;
//
- // Read the DOS image header to check for it's existance
+ // Read the DOS image header to check for its existence
//
Size = sizeof (EFI_IMAGE_DOS_HEADER);
Status = ImageContext->ImageRead (
@@ -1169,49 +1169,49 @@ PeCoffLoaderLoadImage (
if (DirectoryEntry->Size != 0) {
Base = PeCoffLoaderImageAddress (ImageContext, DirectoryEntry->VirtualAddress);
-
- ResourceDirectory = (EFI_IMAGE_RESOURCE_DIRECTORY *) Base;
- ResourceDirectoryEntry = (EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY *) (ResourceDirectory + 1);
-
- for (Index = 0; Index < ResourceDirectory->NumberOfNamedEntries; Index++) {
- if (ResourceDirectoryEntry->u1.s.NameIsString) {
- ResourceDirectoryString = (EFI_IMAGE_RESOURCE_DIRECTORY_STRING *) (Base + ResourceDirectoryEntry->u1.s.NameOffset);
-
- if (ResourceDirectoryString->Length == 3 &&
- ResourceDirectoryString->String[0] == L'H' &&
- ResourceDirectoryString->String[1] == L'I' &&
- ResourceDirectoryString->String[2] == L'I') {
- //
- // Resource Type "HII" found
- //
- if (ResourceDirectoryEntry->u2.s.DataIsDirectory) {
+ if (Base != NULL) {
+ ResourceDirectory = (EFI_IMAGE_RESOURCE_DIRECTORY *) Base;
+ ResourceDirectoryEntry = (EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY *) (ResourceDirectory + 1);
+
+ for (Index = 0; Index < ResourceDirectory->NumberOfNamedEntries; Index++) {
+ if (ResourceDirectoryEntry->u1.s.NameIsString) {
+ ResourceDirectoryString = (EFI_IMAGE_RESOURCE_DIRECTORY_STRING *) (Base + ResourceDirectoryEntry->u1.s.NameOffset);
+
+ if (ResourceDirectoryString->Length == 3 &&
+ ResourceDirectoryString->String[0] == L'H' &&
+ ResourceDirectoryString->String[1] == L'I' &&
+ ResourceDirectoryString->String[2] == L'I') {
//
- // Move to next level - resource Name
+ // Resource Type "HII" found
//
- ResourceDirectory = (EFI_IMAGE_RESOURCE_DIRECTORY *) (Base + ResourceDirectoryEntry->u2.s.OffsetToDirectory);
- ResourceDirectoryEntry = (EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY *) (ResourceDirectory + 1);
-
if (ResourceDirectoryEntry->u2.s.DataIsDirectory) {
//
- // Move to next level - resource Language
+ // Move to next level - resource Name
//
ResourceDirectory = (EFI_IMAGE_RESOURCE_DIRECTORY *) (Base + ResourceDirectoryEntry->u2.s.OffsetToDirectory);
ResourceDirectoryEntry = (EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY *) (ResourceDirectory + 1);
+
+ if (ResourceDirectoryEntry->u2.s.DataIsDirectory) {
+ //
+ // Move to next level - resource Language
+ //
+ ResourceDirectory = (EFI_IMAGE_RESOURCE_DIRECTORY *) (Base + ResourceDirectoryEntry->u2.s.OffsetToDirectory);
+ ResourceDirectoryEntry = (EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY *) (ResourceDirectory + 1);
+ }
}
- }
- //
- // Now it ought to be resource Data
- //
- if (!ResourceDirectoryEntry->u2.s.DataIsDirectory) {
- ResourceDataEntry = (EFI_IMAGE_RESOURCE_DATA_ENTRY *) (Base + ResourceDirectoryEntry->u2.OffsetToData);
- ImageContext->HiiResourceData = (PHYSICAL_ADDRESS) (UINTN) PeCoffLoaderImageAddress (ImageContext, ResourceDataEntry->OffsetToData);
- break;
+ //
+ // Now it ought to be resource Data
+ //
+ if (!ResourceDirectoryEntry->u2.s.DataIsDirectory) {
+ ResourceDataEntry = (EFI_IMAGE_RESOURCE_DATA_ENTRY *) (Base + ResourceDirectoryEntry->u2.OffsetToData);
+ ImageContext->HiiResourceData = (PHYSICAL_ADDRESS) (UINTN) PeCoffLoaderImageAddress (ImageContext, ResourceDataEntry->OffsetToData);
+ break;
+ }
}
}
+ ResourceDirectoryEntry++;
}
-
- ResourceDirectoryEntry++;
}
}
}