]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c
ShellPkg/for: Fix potential null pointer deference
[mirror_edk2.git] / ShellPkg / Library / UefiShellDriver1CommandsLib / DrvCfg.c
index 609d076da040d06489733469de2b8a1d9520de19..37501d4d3fdcfb5d0abc9864750861e52e1273d1 100644 (file)
@@ -2,7 +2,7 @@
   Main file for DrvCfg shell Driver1 function.\r
 \r
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>\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
@@ -30,7 +30,6 @@ STATIC CONST EFI_GUID *CfgGuidList[] = {&gEfiDriverConfigurationProtocolGuid, &g
   @retval EFI_NOT_FOUND   There was no EFI_HII_HANDLE found for that deviec path.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FindHiiHandleViaDevPath(\r
   IN CONST EFI_DEVICE_PATH_PROTOCOL *DevPath1,\r
   OUT EFI_HII_HANDLE                *HiiHandle,\r
@@ -57,8 +56,11 @@ FindHiiHandleViaDevPath(
   Status = HiiDb->ListPackageLists(HiiDb, EFI_HII_PACKAGE_DEVICE_PATH, NULL, &HandleBufferSize, HandleBuffer);\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
     HandleBuffer = AllocateZeroPool(HandleBufferSize);\r
-    ASSERT (HandleBuffer != NULL);\r
-    Status = HiiDb->ListPackageLists(HiiDb, EFI_HII_PACKAGE_DEVICE_PATH, NULL, &HandleBufferSize, HandleBuffer);\r
+    if (HandleBuffer == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+    } else {\r
+      Status = HiiDb->ListPackageLists (HiiDb, EFI_HII_PACKAGE_DEVICE_PATH, NULL, &HandleBufferSize, HandleBuffer);\r
+    }\r
   }\r
   if (EFI_ERROR(Status)) {\r
     SHELL_FREE_NON_NULL(HandleBuffer);\r
@@ -75,8 +77,12 @@ FindHiiHandleViaDevPath(
     Status = HiiDb->ExportPackageLists(HiiDb, HandleBuffer[LoopVariable], &MainBufferSize, MainBuffer);\r
     if (Status == EFI_BUFFER_TOO_SMALL) {\r
       MainBuffer = AllocateZeroPool(MainBufferSize);\r
-      ASSERT (MainBuffer != NULL);\r
-      Status = HiiDb->ExportPackageLists(HiiDb, HandleBuffer[LoopVariable], &MainBufferSize, MainBuffer);\r
+      if (MainBuffer != NULL) {\r
+        Status = HiiDb->ExportPackageLists (HiiDb, HandleBuffer[LoopVariable], &MainBufferSize, MainBuffer);\r
+      }\r
+    }\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
     }\r
     //\r
     // Enumerate through the block of returned memory.\r
@@ -117,7 +123,6 @@ FindHiiHandleViaDevPath(
   @retval EFI_SUCCESS   The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 ConvertHandleToHiiHandle(\r
   IN CONST EFI_HANDLE           Handle,\r
   OUT EFI_HII_HANDLE            *HiiHandle,\r
@@ -152,7 +157,6 @@ ConvertHandleToHiiHandle(
   @param[in] FileName         The filename to rwite the info to.\r
 **/\r
 SHELL_STATUS\r
-EFIAPI\r
 ConfigToFile(\r
   IN CONST EFI_HANDLE     Handle,\r
   IN CONST CHAR16         *FileName\r
@@ -262,7 +266,6 @@ ConfigToFile(
   @param[in] FileName         The filename to read the info from.\r
 **/\r
 SHELL_STATUS\r
-EFIAPI\r
 ConfigFromFile(\r
   IN       EFI_HANDLE     Handle,\r
   IN CONST CHAR16         *FileName\r
@@ -479,7 +482,6 @@ ConfigFromFile(
   @retval SHELL_INVALID_PARAMETER   A parameter has a invalid value.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 ShellCmdDriverConfigurationProcessActionRequired (\r
   EFI_HANDLE                                DriverImageHandle,\r
   EFI_HANDLE                                ControllerHandle,\r
@@ -547,7 +549,6 @@ ShellCmdDriverConfigurationProcessActionRequired (
   @retval SHELL_INVALID_PARAMETER   A parameter has a invalid value.\r
 **/\r
 SHELL_STATUS\r
-EFIAPI\r
 PreHiiDrvCfg (\r
   IN CONST CHAR8    *Language,\r
   IN BOOLEAN        ForceDefaults,\r
@@ -1055,7 +1056,6 @@ Done:
   @retval SHELL_SUCCESS     The operation was successful.\r
 **/\r
 SHELL_STATUS\r
-EFIAPI\r
 PrintConfigInfoOnAll(\r
   IN CONST BOOLEAN ChildrenToo,\r
   IN CONST CHAR8   *Language,\r
@@ -1205,6 +1205,11 @@ ShellCommandRunDrvCfg (
     }\r
   } \r
   if (ShellStatus == SHELL_SUCCESS) {\r
+    if (ShellCommandLineGetCount(Package) > 4) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"drvcfg");\r
+      ShellStatus = SHELL_INVALID_PARAMETER;\r
+      goto Done;\r
+    }\r
     Lang = ShellCommandLineGetValue(Package, L"-l");\r
     if (Lang != NULL) {\r
       Language = AllocateZeroPool(StrSize(Lang));\r