|
Paolo Bonzini |
2e34e0 |
From: Ruiyu Ni <ruiyu.ni@intel.com>
|
|
Paolo Bonzini |
2e34e0 |
Subject: [PATCH] MdeModulePkg/Bds: Check variable name even *if* OptionNumber is NULL
|
|
Paolo Bonzini |
2e34e0 |
Date: Thu, 16 Nov 2017 18:04:43 +0100
|
|
Paolo Bonzini |
2e34e0 |
|
|
Paolo Bonzini |
2e34e0 |
Current implementation skips to check whether the last four
|
|
Paolo Bonzini |
2e34e0 |
characters are digits when the OptionNumber is NULL.
|
|
Paolo Bonzini |
2e34e0 |
Even worse, it may incorrectly return FALSE when OptionNumber is
|
|
Paolo Bonzini |
2e34e0 |
NULL.
|
|
Paolo Bonzini |
2e34e0 |
|
|
Paolo Bonzini |
2e34e0 |
The patch fixes it to always check the variable name even
|
|
Paolo Bonzini |
2e34e0 |
OptionNumber is NULL.
|
|
Paolo Bonzini |
2e34e0 |
|
|
Paolo Bonzini |
2e34e0 |
Contributed-under: TianoCore Contribution Agreement 1.1
|
|
Paolo Bonzini |
2e34e0 |
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
|
|
Paolo Bonzini |
2e34e0 |
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
|
|
Paolo Bonzini |
2e34e0 |
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
|
|
Paolo Bonzini |
2e34e0 |
(cherry picked from commit 5e6e2dcc380dcd841f6f979fea8c302c80a87ec3)
|
|
Paolo Bonzini |
2e34e0 |
---
|
|
Paolo Bonzini |
2e34e0 |
MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c | 45 +++++++++++++-------
|
|
Paolo Bonzini |
2e34e0 |
1 file changed, 30 insertions(+), 15 deletions(-)
|
|
Paolo Bonzini |
2e34e0 |
|
|
Paolo Bonzini |
2e34e0 |
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
|
|
Paolo Bonzini |
2e34e0 |
index b0a35058d02b..32918caf324c 100644
|
|
Paolo Bonzini |
2e34e0 |
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
|
|
Paolo Bonzini |
2e34e0 |
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
|
|
Paolo Bonzini |
2e34e0 |
@@ -785,6 +785,8 @@ EfiBootManagerIsValidLoadOptionVariableName (
|
|
Paolo Bonzini |
2e34e0 |
UINTN VariableNameLen;
|
|
Paolo Bonzini |
2e34e0 |
UINTN Index;
|
|
Paolo Bonzini |
2e34e0 |
UINTN Uint;
|
|
Paolo Bonzini |
2e34e0 |
+ EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LocalOptionType;
|
|
Paolo Bonzini |
2e34e0 |
+ UINT16 LocalOptionNumber;
|
|
Paolo Bonzini |
2e34e0 |
|
|
Paolo Bonzini |
2e34e0 |
if (VariableName == NULL) {
|
|
Paolo Bonzini |
2e34e0 |
return FALSE;
|
|
Paolo Bonzini |
2e34e0 |
@@ -792,39 +794,52 @@ EfiBootManagerIsValidLoadOptionVariableName (
|
|
Paolo Bonzini |
2e34e0 |
|
|
Paolo Bonzini |
2e34e0 |
VariableNameLen = StrLen (VariableName);
|
|
Paolo Bonzini |
2e34e0 |
|
|
Paolo Bonzini |
2e34e0 |
+ //
|
|
Paolo Bonzini |
2e34e0 |
+ // Return FALSE when the variable name length is too small.
|
|
Paolo Bonzini |
2e34e0 |
+ //
|
|
Paolo Bonzini |
2e34e0 |
if (VariableNameLen <= 4) {
|
|
Paolo Bonzini |
2e34e0 |
return FALSE;
|
|
Paolo Bonzini |
2e34e0 |
}
|
|
Paolo Bonzini |
2e34e0 |
|
|
Paolo Bonzini |
2e34e0 |
- for (Index = 0; Index < ARRAY_SIZE (mBmLoadOptionName); Index++) {
|
|
Paolo Bonzini |
2e34e0 |
- if ((VariableNameLen - 4 == StrLen (mBmLoadOptionName[Index])) &&
|
|
Paolo Bonzini |
2e34e0 |
- (StrnCmp (VariableName, mBmLoadOptionName[Index], VariableNameLen - 4) == 0)
|
|
Paolo Bonzini |
2e34e0 |
+ //
|
|
Paolo Bonzini |
2e34e0 |
+ // Return FALSE when the variable name doesn't start with Driver/SysPrep/Boot/PlatformRecovery.
|
|
Paolo Bonzini |
2e34e0 |
+ //
|
|
Paolo Bonzini |
2e34e0 |
+ for (LocalOptionType = 0; LocalOptionType < ARRAY_SIZE (mBmLoadOptionName); LocalOptionType++) {
|
|
Paolo Bonzini |
2e34e0 |
+ if ((VariableNameLen - 4 == StrLen (mBmLoadOptionName[LocalOptionType])) &&
|
|
Paolo Bonzini |
2e34e0 |
+ (StrnCmp (VariableName, mBmLoadOptionName[LocalOptionType], VariableNameLen - 4) == 0)
|
|
Paolo Bonzini |
2e34e0 |
) {
|
|
Paolo Bonzini |
2e34e0 |
break;
|
|
Paolo Bonzini |
2e34e0 |
}
|
|
Paolo Bonzini |
2e34e0 |
}
|
|
Paolo Bonzini |
2e34e0 |
+ if (LocalOptionType == ARRAY_SIZE (mBmLoadOptionName)) {
|
|
Paolo Bonzini |
2e34e0 |
+ return FALSE;
|
|
Paolo Bonzini |
2e34e0 |
+ }
|
|
Paolo Bonzini |
2e34e0 |
|
|
Paolo Bonzini |
2e34e0 |
- if (Index == ARRAY_SIZE (mBmLoadOptionName)) {
|
|
Paolo Bonzini |
2e34e0 |
+ //
|
|
Paolo Bonzini |
2e34e0 |
+ // Return FALSE when the last four characters are not hex digits.
|
|
Paolo Bonzini |
2e34e0 |
+ //
|
|
Paolo Bonzini |
2e34e0 |
+ LocalOptionNumber = 0;
|
|
Paolo Bonzini |
2e34e0 |
+ for (Index = VariableNameLen - 4; Index < VariableNameLen; Index++) {
|
|
Paolo Bonzini |
2e34e0 |
+ Uint = BmCharToUint (VariableName[Index]);
|
|
Paolo Bonzini |
2e34e0 |
+ if (Uint == -1) {
|
|
Paolo Bonzini |
2e34e0 |
+ break;
|
|
Paolo Bonzini |
2e34e0 |
+ } else {
|
|
Paolo Bonzini |
2e34e0 |
+ LocalOptionNumber = (UINT16) Uint + LocalOptionNumber * 0x10;
|
|
Paolo Bonzini |
2e34e0 |
+ }
|
|
Paolo Bonzini |
2e34e0 |
+ }
|
|
Paolo Bonzini |
2e34e0 |
+ if (Index != VariableNameLen) {
|
|
Paolo Bonzini |
2e34e0 |
return FALSE;
|
|
Paolo Bonzini |
2e34e0 |
}
|
|
Paolo Bonzini |
2e34e0 |
|
|
Paolo Bonzini |
2e34e0 |
if (OptionType != NULL) {
|
|
Paolo Bonzini |
2e34e0 |
- *OptionType = (EFI_BOOT_MANAGER_LOAD_OPTION_TYPE) Index;
|
|
Paolo Bonzini |
2e34e0 |
+ *OptionType = LocalOptionType;
|
|
Paolo Bonzini |
2e34e0 |
}
|
|
Paolo Bonzini |
2e34e0 |
|
|
Paolo Bonzini |
2e34e0 |
if (OptionNumber != NULL) {
|
|
Paolo Bonzini |
2e34e0 |
- *OptionNumber = 0;
|
|
Paolo Bonzini |
2e34e0 |
- for (Index = VariableNameLen - 4; Index < VariableNameLen; Index++) {
|
|
Paolo Bonzini |
2e34e0 |
- Uint = BmCharToUint (VariableName[Index]);
|
|
Paolo Bonzini |
2e34e0 |
- if (Uint == -1) {
|
|
Paolo Bonzini |
2e34e0 |
- break;
|
|
Paolo Bonzini |
2e34e0 |
- } else {
|
|
Paolo Bonzini |
2e34e0 |
- *OptionNumber = (UINT16) Uint + *OptionNumber * 0x10;
|
|
Paolo Bonzini |
2e34e0 |
- }
|
|
Paolo Bonzini |
2e34e0 |
- }
|
|
Paolo Bonzini |
2e34e0 |
+ *OptionNumber = LocalOptionNumber;
|
|
Paolo Bonzini |
2e34e0 |
}
|
|
Paolo Bonzini |
2e34e0 |
|
|
Paolo Bonzini |
2e34e0 |
- return (BOOLEAN) (Index == VariableNameLen);
|
|
Paolo Bonzini |
2e34e0 |
+ return TRUE;
|
|
Paolo Bonzini |
2e34e0 |
}
|
|
Paolo Bonzini |
2e34e0 |
|
|
Paolo Bonzini |
2e34e0 |
/**
|
|
Paolo Bonzini |
2e34e0 |
--
|
|
Paolo Bonzini |
2e34e0 |
2.14.1.3.gb7cf6e02401b
|
|
Paolo Bonzini |
2e34e0 |
|