diff options
-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 ada77d2..0a034cd 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));
//
|