mirror of https://github.com/acidanthera/audk.git
MdeModulePkg/Bds: Check variable name even *if* OptionNumber is NULL
Current implementation skips to check whether the last four characters are digits when the OptionNumber is NULL. Even worse, it may incorrectly return FALSE when OptionNumber is NULL. The patch fixes it to always check the variable name even OptionNumber is NULL. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
parent
618ef6f9ba
commit
5e6e2dcc38
|
@ -785,6 +785,8 @@ EfiBootManagerIsValidLoadOptionVariableName (
|
|||
UINTN VariableNameLen;
|
||||
UINTN Index;
|
||||
UINTN Uint;
|
||||
EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LocalOptionType;
|
||||
UINT16 LocalOptionNumber;
|
||||
|
||||
if (VariableName == NULL) {
|
||||
return FALSE;
|
||||
|
@ -792,39 +794,52 @@ EfiBootManagerIsValidLoadOptionVariableName (
|
|||
|
||||
VariableNameLen = StrLen (VariableName);
|
||||
|
||||
//
|
||||
// Return FALSE when the variable name length is too small.
|
||||
//
|
||||
if (VariableNameLen <= 4) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < ARRAY_SIZE (mBmLoadOptionName); Index++) {
|
||||
if ((VariableNameLen - 4 == StrLen (mBmLoadOptionName[Index])) &&
|
||||
(StrnCmp (VariableName, mBmLoadOptionName[Index], VariableNameLen - 4) == 0)
|
||||
//
|
||||
// Return FALSE when the variable name doesn't start with Driver/SysPrep/Boot/PlatformRecovery.
|
||||
//
|
||||
for (LocalOptionType = 0; LocalOptionType < ARRAY_SIZE (mBmLoadOptionName); LocalOptionType++) {
|
||||
if ((VariableNameLen - 4 == StrLen (mBmLoadOptionName[LocalOptionType])) &&
|
||||
(StrnCmp (VariableName, mBmLoadOptionName[LocalOptionType], VariableNameLen - 4) == 0)
|
||||
) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Index == ARRAY_SIZE (mBmLoadOptionName)) {
|
||||
if (LocalOptionType == ARRAY_SIZE (mBmLoadOptionName)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (OptionType != NULL) {
|
||||
*OptionType = (EFI_BOOT_MANAGER_LOAD_OPTION_TYPE) Index;
|
||||
}
|
||||
|
||||
if (OptionNumber != NULL) {
|
||||
*OptionNumber = 0;
|
||||
//
|
||||
// Return FALSE when the last four characters are not hex digits.
|
||||
//
|
||||
LocalOptionNumber = 0;
|
||||
for (Index = VariableNameLen - 4; Index < VariableNameLen; Index++) {
|
||||
Uint = BmCharToUint (VariableName[Index]);
|
||||
if (Uint == -1) {
|
||||
break;
|
||||
} else {
|
||||
*OptionNumber = (UINT16) Uint + *OptionNumber * 0x10;
|
||||
LocalOptionNumber = (UINT16) Uint + LocalOptionNumber * 0x10;
|
||||
}
|
||||
}
|
||||
if (Index != VariableNameLen) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return (BOOLEAN) (Index == VariableNameLen);
|
||||
if (OptionType != NULL) {
|
||||
*OptionType = LocalOptionType;
|
||||
}
|
||||
|
||||
if (OptionNumber != NULL) {
|
||||
*OptionNumber = LocalOptionNumber;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue