mirror of https://github.com/acidanthera/audk.git
ShellPkg/CommandLib: avoid NULL derefence and memory leak
Since TianoCore EDK2 commitd65f2cea36
("ShellPkg/CommandLib: Locate proper UnicodeCollation instance") in edk2 the UEFI Shell crashes if EFI variable PlatformLang is not defined due to dereferencing gUnicodeCollation gUnicodeCollation (= NULL) in ShellCommandRegisterCommandName(). Furthermore CommandInit() is leaking PlatformLang if gUnicodeCollation != NULL. Close the memory leak and use the first UnicodeCollation instance if PlatfomLang is not defined. Fixes:d65f2cea36
("ShellPkg/CommandLib: Locate proper UnicodeCollation instance") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Zhichao Gao <zhichao.gao@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
This commit is contained in:
parent
17f8c9e97d
commit
8b8e915845
|
@ -74,12 +74,10 @@ CommandInit(
|
|||
EFI_STATUS Status;
|
||||
CHAR8 *PlatformLang;
|
||||
|
||||
GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, (VOID**)&PlatformLang, NULL);
|
||||
if (PlatformLang == NULL) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
if (gUnicodeCollation == NULL) {
|
||||
|
||||
GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, (VOID**)&PlatformLang, NULL);
|
||||
|
||||
Status = gBS->LocateHandleBuffer (
|
||||
ByProtocol,
|
||||
&gEfiUnicodeCollation2ProtocolGuid,
|
||||
|
@ -107,6 +105,14 @@ CommandInit(
|
|||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Without clue provided use the first Unicode Collation2 protocol.
|
||||
//
|
||||
if (PlatformLang == NULL) {
|
||||
gUnicodeCollation = Uc;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Find the best matching matching language from the supported languages
|
||||
// of Unicode Collation2 protocol.
|
||||
|
@ -126,7 +132,9 @@ CommandInit(
|
|||
if (Handles != NULL) {
|
||||
FreePool (Handles);
|
||||
}
|
||||
FreePool (PlatformLang);
|
||||
if (PlatformLang != NULL) {
|
||||
FreePool (PlatformLang);
|
||||
}
|
||||
}
|
||||
|
||||
return (gUnicodeCollation == NULL) ? EFI_UNSUPPORTED : EFI_SUCCESS;
|
||||
|
|
Loading…
Reference in New Issue