summaryrefslogtreecommitdiffstats
path: root/ShellPkg/Library/UefiShellCommandLib
diff options
context:
space:
mode:
authorHeinrich Schuchardt <xypron.glpk@gmx.de>2019-05-10 11:24:19 +0800
committerLiming Gao <liming.gao@intel.com>2019-09-03 15:09:50 +0800
commit8b8e91584555b6193f2099a36502763b47501533 (patch)
tree864b8d57777e8710cd21e2a81c43d3fad31586a1 /ShellPkg/Library/UefiShellCommandLib
parent17f8c9e97d770c74f84194576bcd97322fbed21e (diff)
downloadedk2-8b8e91584555b6193f2099a36502763b47501533.tar.gz
edk2-8b8e91584555b6193f2099a36502763b47501533.tar.bz2
edk2-8b8e91584555b6193f2099a36502763b47501533.zip
ShellPkg/CommandLib: avoid NULL derefence and memory leak
Since TianoCore EDK2 commit d65f2cea36d1 ("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: d65f2cea36d1 ("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>
Diffstat (limited to 'ShellPkg/Library/UefiShellCommandLib')
-rw-r--r--ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
index 4635df40bb..826ced30a8 100644
--- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
+++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
@@ -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,
@@ -108,6 +106,14 @@ CommandInit(
}
//
+ // 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;