]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
ShellPkg/CommandLib: avoid NULL derefence and memory leak
[mirror_edk2.git] / ShellPkg / Library / UefiShellCommandLib / UefiShellCommandLib.c
index ddc4bb1567c6e52eab7abd50fc8c0e85a5097bf5..826ced30a8c8c0e2b91be8f29ab29867808fd266 100644 (file)
@@ -5,13 +5,7 @@
   (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
   (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 \r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -80,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
@@ -113,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
@@ -132,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