MdeModulePkg/UefiBootManagerLib: API BmIsValidLoadOptionVariableName

Redfine the BmIsValidLoadOptionVariableName function to allow public use. Change name to EfiBootManagerIsValidLoadOptionVariableName to match naming scheme. Check that VariableName is never NULL and allow OptionType and OptionNumber to be optional.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Thomas Palmer <thomas.palmer@hpe.com>
Reviewed-by: Sunny Wang <sunnywang@hpe.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
This commit is contained in:
Thomas Palmer 2016-04-05 03:51:42 +08:00 committed by Ruiyu Ni
parent 716132efb1
commit 3dc5c1ae5c
2 changed files with 46 additions and 15 deletions

View File

@ -2,7 +2,7 @@
Provide Boot Manager related library APIs. Provide Boot Manager related library APIs.
Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -731,4 +731,25 @@ EFIAPI
EfiBootManagerProcessLoadOption ( EfiBootManagerProcessLoadOption (
EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption
); );
/**
Check whether the VariableName is a valid load option variable name
and return the load option type and option number.
@param VariableName The name of the load option variable.
@param OptionType Return the load option type.
@param OptionNumber Return the load option number.
@retval TRUE The variable name is valid; The load option type and
load option number are returned.
@retval FALSE The variable name is NOT valid.
**/
BOOLEAN
EFIAPI
EfiBootManagerIsValidLoadOptionVariableName (
IN CHAR16 *VariableName,
OUT EFI_BOOT_MANAGER_LOAD_OPTION_TYPE *OptionType OPTIONAL,
OUT UINT16 *OptionNumber OPTIONAL
);
#endif #endif

View File

@ -2,7 +2,7 @@
Load option library functions which relate with creating and processing load options. Load option library functions which relate with creating and processing load options.
Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR> Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -775,16 +775,21 @@ BmValidateOption (
@retval FALSE The variable name is NOT valid. @retval FALSE The variable name is NOT valid.
**/ **/
BOOLEAN BOOLEAN
BmIsValidLoadOptionVariableName ( EFIAPI
EfiBootManagerIsValidLoadOptionVariableName (
IN CHAR16 *VariableName, IN CHAR16 *VariableName,
OUT EFI_BOOT_MANAGER_LOAD_OPTION_TYPE *OptionType, OUT EFI_BOOT_MANAGER_LOAD_OPTION_TYPE *OptionType OPTIONAL,
OUT UINT16 *OptionNumber OUT UINT16 *OptionNumber OPTIONAL
) )
{ {
UINTN VariableNameLen; UINTN VariableNameLen;
UINTN Index; UINTN Index;
UINTN Uint; UINTN Uint;
if (VariableName == NULL) {
return FALSE;
}
VariableNameLen = StrLen (VariableName); VariableNameLen = StrLen (VariableName);
if (VariableNameLen <= 4) { if (VariableNameLen <= 4) {
@ -803,14 +808,19 @@ BmIsValidLoadOptionVariableName (
return FALSE; return FALSE;
} }
*OptionType = (EFI_BOOT_MANAGER_LOAD_OPTION_TYPE) Index; if (OptionType != NULL) {
*OptionNumber = 0; *OptionType = (EFI_BOOT_MANAGER_LOAD_OPTION_TYPE) Index;
for (Index = VariableNameLen - 4; Index < VariableNameLen; Index++) { }
Uint = BmCharToUint (VariableName[Index]);
if (Uint == -1) { if (OptionNumber != NULL) {
break; *OptionNumber = 0;
} else { for (Index = VariableNameLen - 4; Index < VariableNameLen; Index++) {
*OptionNumber = (UINT16) Uint + *OptionNumber * 0x10; Uint = BmCharToUint (VariableName[Index]);
if (Uint == -1) {
break;
} else {
*OptionNumber = (UINT16) Uint + *OptionNumber * 0x10;
}
} }
} }
@ -853,7 +863,7 @@ EfiBootManagerVariableToLoadOptionEx (
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (!BmIsValidLoadOptionVariableName (VariableName, &OptionType, &OptionNumber)) { if (!EfiBootManagerIsValidLoadOptionVariableName (VariableName, &OptionType, &OptionNumber)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -979,7 +989,7 @@ BmCollectLoadOptions (
if (CompareGuid (Guid, Param->Guid) && ( if (CompareGuid (Guid, Param->Guid) && (
Param->OptionType == LoadOptionTypePlatformRecovery && Param->OptionType == LoadOptionTypePlatformRecovery &&
BmIsValidLoadOptionVariableName (Name, &OptionType, &OptionNumber) && EfiBootManagerIsValidLoadOptionVariableName (Name, &OptionType, &OptionNumber) &&
OptionType == LoadOptionTypePlatformRecovery OptionType == LoadOptionTypePlatformRecovery
)) { )) {
Status = EfiBootManagerVariableToLoadOptionEx (Name, Guid, &Option); Status = EfiBootManagerVariableToLoadOptionEx (Name, Guid, &Option);