]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg/CommandLib: avoid NULL derefence and memory leak
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Fri, 10 May 2019 03:24:19 +0000 (11:24 +0800)
committerLiming Gao <liming.gao@intel.com>
Tue, 3 Sep 2019 07:09:50 +0000 (15:09 +0800)
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>
ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c

index 4635df40bbdc49397a733ac6a17de2b1d7ecb5fc..826ced30a8c8c0e2b91be8f29ab29867808fd266 100644 (file)
@@ -74,12 +74,10 @@ CommandInit(
   EFI_STATUS                      Status;\r
   CHAR8                           *PlatformLang;\r
 \r
-  GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, (VOID**)&PlatformLang, NULL);\r
-  if (PlatformLang == NULL) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
   if (gUnicodeCollation == NULL) {\r
+\r
+    GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, (VOID**)&PlatformLang, NULL);\r
+\r
     Status = gBS->LocateHandleBuffer (\r
                     ByProtocol,\r
                     &gEfiUnicodeCollation2ProtocolGuid,\r
@@ -107,6 +105,14 @@ CommandInit(
         continue;\r
       }\r
 \r
+      //\r
+      // Without clue provided use the first Unicode Collation2 protocol.\r
+      //\r
+      if (PlatformLang == NULL) {\r
+        gUnicodeCollation = Uc;\r
+        break;\r
+      }\r
+\r
       //\r
       // Find the best matching matching language from the supported languages\r
       // of Unicode Collation2 protocol.\r
@@ -126,7 +132,9 @@ CommandInit(
     if (Handles != NULL) {\r
       FreePool (Handles);\r
     }\r
-    FreePool (PlatformLang);\r
+    if (PlatformLang != NULL) {\r
+      FreePool (PlatformLang);\r
+    }\r
   }\r
 \r
   return (gUnicodeCollation == NULL) ? EFI_UNSUPPORTED : EFI_SUCCESS;\r