]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg/For: Handle memory allocation failure
authorRuiyu Ni <ruiyu.ni@intel.com>
Wed, 13 Jul 2016 07:45:08 +0000 (15:45 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Mon, 18 Jul 2016 02:55:48 +0000 (10:55 +0800)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
ShellPkg/Library/UefiShellLevel1CommandsLib/For.c

index cbf05170135df46955a0fd42b96de5833441b545..6cfe8a78feadea9770e0944621072c7f1a6caa2a 100644 (file)
@@ -2,7 +2,7 @@
   Main file for endfor and for shell level 1 functions.\r
 \r
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 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
@@ -414,7 +414,10 @@ ShellCommandRunFor (
         NewSize = StrSize(ArgSet);\r
         NewSize += sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]);\r
         Info = AllocateZeroPool(NewSize);\r
-        ASSERT(Info != NULL);\r
+        if (Info == NULL) {\r
+          FreePool (ArgSet);\r
+          return SHELL_OUT_OF_RESOURCES;\r
+        }\r
         Info->Signature = SHELL_FOR_INFO_SIGNATURE;\r
         CopyMem(Info->Set, ArgSet, StrSize(ArgSet));\r
         NewSize = StrSize(gEfiShellParametersProtocol->Argv[1]);\r
@@ -458,7 +461,10 @@ ShellCommandRunFor (
         // set up for a 'run' for loop\r
         //\r
         Info = AllocateZeroPool(sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]));\r
-        ASSERT(Info != NULL);\r
+        if (Info == NULL) {\r
+          FreePool (ArgSet);\r
+          return SHELL_OUT_OF_RESOURCES;\r
+        }\r
         Info->Signature = SHELL_FOR_INFO_SIGNATURE;\r
         CopyMem(Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize(gEfiShellParametersProtocol->Argv[1]));\r
         Info->ReplacementName = Info->Set;\r