Add logic to validate variable before use it.

Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Jiewen Yao <jiewen,yao@intel.com>
Reviewed-by: Michael D. Kinney <michael.d.kinney@intel.com>
 

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13323 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
ydong10 2012-05-18 02:24:25 +00:00
parent 7ea2285209
commit a95b6045c3
2 changed files with 96 additions and 2 deletions

View File

@ -124,6 +124,53 @@ PeimInitializeDxeIpl (
return Status; return Status;
} }
/**
Validate variable data for the MemoryTypeInformation.
@param MemoryData Variable data.
@param MemoryDataSize Variable data length.
@return TRUE The variable data is valid.
@return FALSE The variable data is invalid.
**/
BOOLEAN
ValidateMemoryTypeInfoVariable (
IN EFI_MEMORY_TYPE_INFORMATION *MemoryData,
IN UINTN MemoryDataSize
)
{
UINTN Count;
UINTN Index;
// Check the input parameter.
if (MemoryData == NULL) {
return FALSE;
}
// Get Count
Count = MemoryDataSize / sizeof (*MemoryData);
// Check Size
if (Count * sizeof(*MemoryData) != MemoryDataSize) {
return FALSE;
}
// Check last entry type filed.
if (MemoryData[Count - 1].Type != EfiMaxMemoryType) {
return FALSE;
}
// Check the type filed.
for (Index = 0; Index < Count - 1; Index++) {
if (MemoryData[Index].Type >= EfiMaxMemoryType) {
return FALSE;
}
}
return TRUE;
}
/** /**
Main entry point to last PEIM. Main entry point to last PEIM.
@ -214,7 +261,7 @@ DxeLoadCore (
&DataSize, &DataSize,
&MemoryData &MemoryData
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status) && ValidateMemoryTypeInfoVariable(MemoryData, DataSize)) {
// //
// Build the GUID'd HOB for DXE // Build the GUID'd HOB for DXE
// //

View File

@ -49,6 +49,53 @@ EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {
{ EfiMaxMemoryType, 0 } { EfiMaxMemoryType, 0 }
}; };
/**
Validate variable data for the MemoryTypeInformation.
@param MemoryData Variable data.
@param MemoryDataSize Variable data length.
@return TRUE The variable data is valid.
@return FALSE The variable data is invalid.
**/
BOOLEAN
ValidateMemoryTypeInfoVariable (
IN EFI_MEMORY_TYPE_INFORMATION *MemoryData,
IN UINTN MemoryDataSize
)
{
UINTN Count;
UINTN Index;
// Check the input parameter.
if (MemoryData == NULL) {
return FALSE;
}
// Get Count
Count = MemoryDataSize / sizeof (*MemoryData);
// Check Size
if (Count * sizeof(*MemoryData) != MemoryDataSize) {
return FALSE;
}
// Check last entry type filed.
if (MemoryData[Count - 1].Type != EfiMaxMemoryType) {
return FALSE;
}
// Check the type filed.
for (Index = 0; Index < Count - 1; Index++) {
if (MemoryData[Index].Type >= EfiMaxMemoryType) {
return FALSE;
}
}
return TRUE;
}
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
PeimInitializeWinNtAutoScan ( PeimInitializeWinNtAutoScan (
@ -153,7 +200,7 @@ Returns:
&DataSize, &DataSize,
&MemoryData &MemoryData
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status) || !ValidateMemoryTypeInfoVariable(MemoryData, DataSize)) {
// //
// Create Memory Type Information HOB // Create Memory Type Information HOB
// //