diff options
author | ydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524> | 2012-05-25 05:04:13 +0000 |
---|---|---|
committer | ydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524> | 2012-05-25 05:04:13 +0000 |
commit | 3e8670718dc8d10266a5bedfad2bc1de1ec3149a (patch) | |
tree | ae925fb93997ff61a48e2c75e909939e3307f62f | |
parent | 097e8d6839143fc020a860885116024ce096ea32 (diff) | |
download | edk2-platforms-3e8670718dc8d10266a5bedfad2bc1de1ec3149a.tar.xz |
Refine logic about validate boot option.
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13362 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r-- | IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c | 54 |
1 files changed, 13 insertions, 41 deletions
diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c index ada77d26de..0a034cda96 100644 --- a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c +++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c @@ -455,7 +455,7 @@ GetDevicePathSizeEx ( bigger than MaxStringLen, return length 0 to indicate that this is an
invalidate string.
- This function returns the number of Unicode characters in the Null-terminated
+ This function returns the byte length of Unicode characters in the Null-terminated
Unicode string specified by String.
If String is NULL, then ASSERT().
@@ -479,13 +479,13 @@ StrSizeEx ( ASSERT (String != NULL && MaxStringLen != 0);
ASSERT (((UINTN) String & BIT0) == 0);
- for (Length = 0; *String != L'\0' && MaxStringLen != Length; String++, Length++);
+ for (Length = 0; *String != L'\0' && MaxStringLen != Length; String++, Length+=2);
if (*String != L'\0' && MaxStringLen == Length) {
return 0;
}
- return (Length + 1) * sizeof (*String);
+ return Length + 2;
}
/**
@@ -507,9 +507,12 @@ ValidateOption ( UINT16 FilePathSize;
UINT8 *TempPtr;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
- EFI_DEVICE_PATH_PROTOCOL *TempPath;
UINTN TempSize;
+ if (VariableSize <= sizeof (UINT16) + sizeof (UINT32)) {
+ return FALSE;
+ }
+
//
// Skip the option attribute
//
@@ -525,14 +528,14 @@ ValidateOption ( //
// Get the option's description string size
//
- TempSize = StrSizeEx ((CHAR16 *) TempPtr, VariableSize);
+ TempSize = StrSizeEx ((CHAR16 *) TempPtr, VariableSize - sizeof (UINT16) - sizeof (UINT32));
TempPtr += TempSize;
//
// Get the option's device path
//
DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
- TempPtr += FilePathSize;
+ TempPtr += FilePathSize;
//
// Validation boot option variable.
@@ -541,21 +544,11 @@ ValidateOption ( return FALSE;
}
- if (TempSize + FilePathSize + sizeof (UINT16) + sizeof (UINT16) > VariableSize) {
+ if (TempSize + FilePathSize + sizeof (UINT16) + sizeof (UINT32) > VariableSize) {
return FALSE;
}
- TempPath = DevicePath;
- while (FilePathSize > 0) {
- TempSize = GetDevicePathSizeEx (TempPath, FilePathSize);
- if (TempSize == 0) {
- return FALSE;
- }
- FilePathSize = (UINT16) (FilePathSize - TempSize);
- TempPath += TempSize;
- }
-
- return TRUE;
+ return GetDevicePathSizeEx (DevicePath, FilePathSize) != 0;
}
/**
@@ -608,13 +601,12 @@ BdsLibVariableToOption ( UINT8 *TempPtr;
UINTN VariableSize;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
- EFI_DEVICE_PATH_PROTOCOL *TempPath;
BDS_COMMON_OPTION *Option;
VOID *LoadOptions;
UINT32 LoadOptionsSize;
CHAR16 *Description;
UINT8 NumOff;
- UINTN TempSize;
+
//
// Read the variable. We will never free this data.
//
@@ -659,11 +651,7 @@ BdsLibVariableToOption ( //
// Get the option's description string size
//
- TempSize = StrSizeEx ((CHAR16 *) TempPtr, VariableSize);
- if (TempSize == 0) {
- return NULL;
- }
- TempPtr += TempSize;
+ TempPtr += StrSize((CHAR16 *) TempPtr);
//
// Get the option's device path
@@ -672,25 +660,9 @@ BdsLibVariableToOption ( TempPtr += FilePathSize;
//
- // Validation device path.
- //
- TempPath = DevicePath;
- while (FilePathSize > 0) {
- TempSize = GetDevicePathSizeEx (TempPath, FilePathSize);
- if (TempSize == 0) {
- return NULL;
- }
- FilePathSize = (UINT16) (FilePathSize - TempSize);
- TempPath += TempSize;
- }
-
- //
// Get load opion data.
//
LoadOptions = TempPtr;
- if (VariableSize < (UINTN)(TempPtr - Variable)) {
- return NULL;
- }
LoadOptionsSize = (UINT32) (VariableSize - (UINTN) (TempPtr - Variable));
//
|