Add logic to validate console variables when enter BDS.
Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13322 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
17aa79bfa7
commit
7ea2285209
|
@ -274,6 +274,112 @@ BdsBootDeviceSelect (
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Validate the device path instance.
|
||||||
|
|
||||||
|
Only base on the length filed in the device path node to validate the device path.
|
||||||
|
|
||||||
|
@param DevicePath A pointer to a device path data structure.
|
||||||
|
@param MaxSize Max valid device path size. If big than this size,
|
||||||
|
return error.
|
||||||
|
|
||||||
|
@retval TRUE An valid device path.
|
||||||
|
@retval FALSE An invalid device path.
|
||||||
|
|
||||||
|
**/
|
||||||
|
BOOLEAN
|
||||||
|
IsValidDevicePath (
|
||||||
|
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||||
|
IN UINTN MaxSize
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINTN Size;
|
||||||
|
UINTN NodeSize;
|
||||||
|
|
||||||
|
if (DevicePath == NULL) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Size = 0;
|
||||||
|
|
||||||
|
while (!IsDevicePathEnd (DevicePath)) {
|
||||||
|
NodeSize = DevicePathNodeLength (DevicePath);
|
||||||
|
if (NodeSize < END_DEVICE_PATH_LENGTH) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Size += NodeSize;
|
||||||
|
if (Size > MaxSize) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
DevicePath = NextDevicePathNode (DevicePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
Size += DevicePathNodeLength (DevicePath);
|
||||||
|
if (Size > MaxSize) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
Validate input console variable data.
|
||||||
|
|
||||||
|
If found the device path is not a valid device path, remove the variable.
|
||||||
|
|
||||||
|
@param VariableName Input console variable name.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
VOID
|
||||||
|
BdsFormalizeConsoleVariable (
|
||||||
|
IN CHAR16 *VariableName
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||||
|
UINTN VariableSize;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
DevicePath = BdsLibGetVariableAndSize (
|
||||||
|
VariableName,
|
||||||
|
&gEfiGlobalVariableGuid,
|
||||||
|
&VariableSize
|
||||||
|
);
|
||||||
|
if (!IsValidDevicePath (DevicePath, VariableSize)) {
|
||||||
|
Status = gRT->SetVariable (
|
||||||
|
VariableName,
|
||||||
|
&gEfiGlobalVariableGuid,
|
||||||
|
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
|
||||||
|
0,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
Validate variables.
|
||||||
|
|
||||||
|
If found the device path is not a valid device path, remove the variable.
|
||||||
|
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
BdsFormalizeEfiGlobalVariable (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate Console variable.
|
||||||
|
//
|
||||||
|
BdsFormalizeConsoleVariable (L"ConIn");
|
||||||
|
BdsFormalizeConsoleVariable (L"ConOut");
|
||||||
|
BdsFormalizeConsoleVariable (L"ErrOut");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
Service routine for BdsInstance->Entry(). Devices are connected, the
|
Service routine for BdsInstance->Entry(). Devices are connected, the
|
||||||
|
@ -323,6 +429,11 @@ BdsEntry (
|
||||||
//
|
//
|
||||||
gBS->CalculateCrc32 ((VOID *)gST, sizeof(EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);
|
gBS->CalculateCrc32 ((VOID *)gST, sizeof(EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Variable.
|
||||||
|
//
|
||||||
|
BdsFormalizeEfiGlobalVariable();
|
||||||
|
|
||||||
//
|
//
|
||||||
// Do the platform init, can be customized by OEM/IBV
|
// Do the platform init, can be customized by OEM/IBV
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue