]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Verify memory allocations without ASSERT.
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 10 Oct 2011 17:26:25 +0000 (17:26 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 10 Oct 2011 17:26:25 +0000 (17:26 +0000)
signed-off-by: jcarsey
reviewed-by: geekboy15a

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12522 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
ShellPkg/Library/UefiShellLib/UefiShellLib.c

index c753702e816be46ff7489d552ff6cb72049b22fb..74beb093c41de42e91c6398fb3ebf96a612922c2 100644 (file)
@@ -96,78 +96,47 @@ ShellCommandRunCd (
       }\r
     } else {\r
       Param1Copy = CatSPrint(NULL, L"%s", Param1, NULL);\r
-      Param1Copy = PathCleanUpDirectories(Param1Copy);\r
-      if (StrCmp(Param1Copy, L".") == 0) {\r
-        //\r
-        // nothing to do... change to current directory\r
-        //\r
-      } else if (StrCmp(Param1Copy, L"..") == 0) {\r
-        //\r
-        // Change up one directory...\r
-        //\r
-        Directory = ShellGetCurrentDir(NULL);\r
-        if (Directory == NULL) {\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
-          ShellStatus = SHELL_NOT_FOUND;\r
-        } else {\r
-          Drive = GetFullyQualifiedPath(Directory);\r
-          PathRemoveLastItem(Drive);\r
-        }\r
-        if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r
+      if (Param1Copy != NULL) {\r
+        Param1Copy = PathCleanUpDirectories(Param1Copy);\r
+      }\r
+      if (Param1Copy != NULL) {\r
+        if (StrCmp(Param1Copy, L".") == 0) {\r
           //\r
-          // change directory on current drive letter\r
+          // nothing to do... change to current directory\r
           //\r
-          Status = gEfiShellProtocol->SetCurDir(NULL, Drive);\r
-          if (Status == EFI_NOT_FOUND) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
-            ShellStatus = SHELL_NOT_FOUND;\r
-          }\r
-        }\r
-      } else if (StrCmp(Param1Copy, L"\\") == 0) {\r
-        //\r
-        // Move to root of current drive\r
-        //\r
-        Directory = ShellGetCurrentDir(NULL);\r
-        if (Directory == NULL) {\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
-          ShellStatus = SHELL_NOT_FOUND;\r
-        } else {\r
-          Drive = GetFullyQualifiedPath(Directory);\r
-          while (PathRemoveLastItem(Drive)) ;\r
-        }\r
-        if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r
+        } else if (StrCmp(Param1Copy, L"..") == 0) {\r
           //\r
-          // change directory on current drive letter\r
+          // Change up one directory...\r
           //\r
-          Status = gEfiShellProtocol->SetCurDir(NULL, Drive);\r
-          if (Status == EFI_NOT_FOUND) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+          Directory = ShellGetCurrentDir(NULL);\r
+          if (Directory == NULL) {\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
             ShellStatus = SHELL_NOT_FOUND;\r
-          }\r
-        }\r
-      } else if (StrStr(Param1Copy, L":") == NULL) {\r
-        if (ShellGetCurrentDir(NULL) == NULL) {\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
-          ShellStatus = SHELL_NOT_FOUND;\r
-        } else {\r
-          ASSERT((Drive == NULL && DriveSize == 0) || (Drive != NULL));\r
-          Drive = StrnCatGrow(&Drive, &DriveSize, ShellGetCurrentDir(NULL), 0);\r
-          if (*Param1Copy == L'\\') {\r
-            while (PathRemoveLastItem(Drive)) ;\r
-            Drive = StrnCatGrow(&Drive, &DriveSize, Param1Copy+1, 0);\r
           } else {\r
-            Drive = StrnCatGrow(&Drive, &DriveSize, Param1Copy, 0);\r
+            Drive = GetFullyQualifiedPath(Directory);\r
+            PathRemoveLastItem(Drive);\r
           }\r
+          if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r
+            //\r
+            // change directory on current drive letter\r
+            //\r
+            Status = gEfiShellProtocol->SetCurDir(NULL, Drive);\r
+            if (Status == EFI_NOT_FOUND) {\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+              ShellStatus = SHELL_NOT_FOUND;\r
+            }\r
+          }\r
+        } else if (StrCmp(Param1Copy, L"\\") == 0) {\r
           //\r
-          // Verify that this is a valid directory\r
+          // Move to root of current drive\r
           //\r
-          Status = gEfiShellProtocol->OpenFileByName(Drive, &Handle, EFI_FILE_MODE_READ);\r
-          if (EFI_ERROR(Status)) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Drive);\r
-            ShellStatus = SHELL_NOT_FOUND;\r
-          } else if (EFI_ERROR(FileHandleIsDirectory(Handle))) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, Drive);\r
+          Directory = ShellGetCurrentDir(NULL);\r
+          if (Directory == NULL) {\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
             ShellStatus = SHELL_NOT_FOUND;\r
+          } else {\r
+            Drive = GetFullyQualifiedPath(Directory);\r
+            while (PathRemoveLastItem(Drive)) ;\r
           }\r
           if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r
             //\r
@@ -179,42 +148,77 @@ ShellCommandRunCd (
               ShellStatus = SHELL_NOT_FOUND;\r
             }\r
           }\r
-          if (Handle != NULL) {\r
-            gEfiShellProtocol->CloseFile(Handle);\r
-            DEBUG_CODE(Handle = NULL;);\r
+        } else if (StrStr(Param1Copy, L":") == NULL) {\r
+          if (ShellGetCurrentDir(NULL) == NULL) {\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
+            ShellStatus = SHELL_NOT_FOUND;\r
+          } else {\r
+            ASSERT((Drive == NULL && DriveSize == 0) || (Drive != NULL));\r
+            Drive = StrnCatGrow(&Drive, &DriveSize, ShellGetCurrentDir(NULL), 0);\r
+            if (*Param1Copy == L'\\') {\r
+              while (PathRemoveLastItem(Drive)) ;\r
+              Drive = StrnCatGrow(&Drive, &DriveSize, Param1Copy+1, 0);\r
+            } else {\r
+              Drive = StrnCatGrow(&Drive, &DriveSize, Param1Copy, 0);\r
+            }\r
+            //\r
+            // Verify that this is a valid directory\r
+            //\r
+            Status = gEfiShellProtocol->OpenFileByName(Drive, &Handle, EFI_FILE_MODE_READ);\r
+            if (EFI_ERROR(Status)) {\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Drive);\r
+              ShellStatus = SHELL_NOT_FOUND;\r
+            } else if (EFI_ERROR(FileHandleIsDirectory(Handle))) {\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, Drive);\r
+              ShellStatus = SHELL_NOT_FOUND;\r
+            }\r
+            if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r
+              //\r
+              // change directory on current drive letter\r
+              //\r
+              Status = gEfiShellProtocol->SetCurDir(NULL, Drive);\r
+              if (Status == EFI_NOT_FOUND) {\r
+                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+                ShellStatus = SHELL_NOT_FOUND;\r
+              }\r
+            }\r
+            if (Handle != NULL) {\r
+              gEfiShellProtocol->CloseFile(Handle);\r
+              DEBUG_CODE(Handle = NULL;);\r
+            }\r
           }\r
-        }\r
-      } else {\r
-        //\r
-        // change directory on other drive letter\r
-        //\r
-        Drive = AllocateZeroPool(StrSize(Param1Copy));\r
-        if (Drive == NULL) {\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);\r
-          ShellStatus = SHELL_OUT_OF_RESOURCES;\r
         } else {\r
-          Drive = StrCpy(Drive, Param1Copy);\r
-          Path = StrStr(Drive, L":");\r
-          ASSERT(Path != NULL);\r
-          if (*(Path+1) == CHAR_NULL) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
-            ShellStatus = SHELL_NOT_FOUND;\r
+          //\r
+          // change directory on other drive letter\r
+          //\r
+          Drive = AllocateZeroPool(StrSize(Param1Copy));\r
+          if (Drive == NULL) {\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);\r
+            ShellStatus = SHELL_OUT_OF_RESOURCES;\r
           } else {\r
-            *(Path+1) = CHAR_NULL;\r
-            if (Path == Drive + StrLen(Drive)) {\r
+            Drive = StrCpy(Drive, Param1Copy);\r
+            Path = StrStr(Drive, L":");\r
+            ASSERT(Path != NULL);\r
+            if (*(Path+1) == CHAR_NULL) {\r
               ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
               ShellStatus = SHELL_NOT_FOUND;\r
             } else {\r
-              Status = gEfiShellProtocol->SetCurDir(Drive, Path+2);\r
-              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_PRINT), gShellLevel2HiiHandle, ShellGetCurrentDir(Drive));\r
+              *(Path+1) = CHAR_NULL;\r
+              if (Path == Drive + StrLen(Drive)) {\r
+                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+                ShellStatus = SHELL_NOT_FOUND;\r
+              } else {\r
+                Status = gEfiShellProtocol->SetCurDir(Drive, Path+2);\r
+                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_PRINT), gShellLevel2HiiHandle, ShellGetCurrentDir(Drive));\r
+              }\r
+            }\r
+            if (Status == EFI_NOT_FOUND) {\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+              Status = SHELL_NOT_FOUND;\r
+            } else if (EFI_ERROR(Status)) {\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1Copy);\r
+              Status = SHELL_NOT_FOUND;\r
             }\r
-          }\r
-          if (Status == EFI_NOT_FOUND) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
-            Status = SHELL_NOT_FOUND;\r
-          } else if (EFI_ERROR(Status)) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1Copy);\r
-            Status = SHELL_NOT_FOUND;\r
           }\r
         }\r
       }\r
index b83eede5a90cec90289a1854fa5438931b6b1afe..a93ef33c039c02dd602add040a5ac28855b8ee59 100644 (file)
@@ -120,9 +120,10 @@ IsValidMove(
   @param[in, out] DestPathPointer  A pointer to the callee allocated final path.\r
   @param[in] Cwd                   A pointer to the current working directory.\r
 \r
-  @retval EFI_INVALID_PARAMETR  The DestDir could not be resolved to a location.\r
-  @retval EFI_INVALID_PARAMETR  The DestDir could be resolved to more than 1 location.\r
-  @retval EFI_SUCCESS           The operation was sucessful.\r
+  @retval SHELL_INVALID_PARAMETER  The DestDir could not be resolved to a location.\r
+  @retval SHELL_INVALID_PARAMETER  The DestDir could be resolved to more than 1 location.\r
+  @retval SHELL_INVALID_PARAMETER  Cwd is required and is NULL.\r
+  @retval SHELL_SUCCESS            The operation was sucessful.\r
 **/\r
 SHELL_STATUS\r
 EFIAPI\r
@@ -143,6 +144,9 @@ GetDestinationLocation(
   DestPath = NULL;\r
 \r
   if (StrStr(DestDir, L"\\") == DestDir) {\r
+    if (Cwd == NULL) {\r
+      return SHELL_INVALID_PARAMETER;\r
+    }\r
     DestPath = AllocateZeroPool(StrSize(Cwd));\r
     if (DestPath == NULL) {\r
       return (SHELL_OUT_OF_RESOURCES);\r
@@ -161,6 +165,10 @@ GetDestinationLocation(
     // Not existing... must be renaming\r
     //\r
     if ((TempLocation = StrStr(DestDir, L":")) == NULL) {\r
+      if (Cwd == NULL) {\r
+        ShellCloseFileMetaArg(&DestList);\r
+        return (SHELL_INVALID_PARAMETER);\r
+      }\r
       NewSize = StrSize(Cwd);\r
       NewSize += StrSize(DestDir);\r
       DestPath = AllocateZeroPool(NewSize);\r
index 44e83ba254808cde35e0b10969f99c7932dfc191..aa40bbf22fdca8ad89397c0ef4d64e6750d6914f 100644 (file)
@@ -179,6 +179,7 @@ ShellCommandRunDate (
   EFI_TIME      TheTime;\r
   CHAR16        *ProblemParam;\r
   SHELL_STATUS  ShellStatus;\r
+  CONST CHAR16  *Param1;\r
 \r
   ShellStatus  = SHELL_SUCCESS;\r
   ProblemParam = NULL;\r
@@ -238,9 +239,14 @@ ShellCommandRunDate (
           //\r
           // perform level 3 operation here.\r
           //\r
-          ShellStatus = CheckAndSetDate(ShellCommandLineGetRawValue(Package, 1));\r
+          Param1 = ShellCommandLineGetRawValue(Package, 1);\r
+          if (Param1 == NULL) {\r
+            ShellStatus = SHELL_INVALID_PARAMETER;\r
+          } else {\r
+            ShellStatus = CheckAndSetDate(Param1);\r
+          }\r
           if (ShellStatus != SHELL_SUCCESS) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, Param1);\r
             ShellStatus = SHELL_INVALID_PARAMETER;\r
           }\r
         }\r
index 06e2386378296df769c07a29ea9234ec752e7728..474aecb7ae5ebffcd11e7463ff727738d24cb1a2 100644 (file)
@@ -84,6 +84,8 @@ ShellIsDecimalDigitCharacter (
   Helper function to find ShellEnvironment2 for constructor.\r
 \r
   @param[in] ImageHandle    A copy of the calling image's handle.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES    Memory allocation failed.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -123,7 +125,9 @@ ShellFindSE2 (
     //\r
     if (Status == EFI_BUFFER_TOO_SMALL) {\r
       Buffer = (EFI_HANDLE*)AllocateZeroPool(BufferSize);\r
-      ASSERT(Buffer != NULL);\r
+      if (Buffer == NULL) {\r
+        return (EFI_OUT_OF_RESOURCES);\r
+      }\r
       Status = gBS->LocateHandle (ByProtocol,\r
                                   &gEfiShellEnvironment2Guid,\r
                                   NULL, // ignored for ByProtocol\r
@@ -1360,8 +1364,9 @@ InternalShellConvertFileListType (
     // allocate a new EFI_SHELL_FILE_INFO object\r
     //\r
     NewInfo               = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
-    ASSERT(NewInfo != NULL);\r
     if (NewInfo == NULL) {\r
+      ShellCloseFileMetaArg(&(EFI_SHELL_FILE_INFO*)ListHead);\r
+      ListHead = NULL;\r
       break;\r
     }\r
 \r
@@ -1384,9 +1389,11 @@ InternalShellConvertFileListType (
     //\r
     // make sure all the memory allocations were sucessful\r
     //\r
-    ASSERT(NewInfo->FullName != NULL);\r
-    ASSERT(NewInfo->FileName != NULL);\r
-    ASSERT(NewInfo->Info     != NULL);\r
+    if (NULL == NewInfo->FullName || NewInfo->FileName == NULL || NewInfo->Info == NULL) {\r
+      ShellCloseFileMetaArg(&(EFI_SHELL_FILE_INFO*)ListHead);\r
+      ListHead = NULL;\r
+      break;\r
+    }\r
 \r
     //\r
     // Copt the strings and structure\r
@@ -1612,7 +1619,6 @@ ShellFindFilePath (
     Size = StrSize(Path);\r
     Size += StrSize(FileName);\r
     TestPath = AllocateZeroPool(Size);\r
-    ASSERT(TestPath != NULL);\r
     if (TestPath == NULL) {\r
       return (NULL);\r
     }\r
@@ -1719,7 +1725,6 @@ ShellFindFilePathEx (
   Size =  StrSize(FileName);\r
   Size += StrSize(FileExtension);\r
   TestPath = AllocateZeroPool(Size);\r
-  ASSERT(TestPath != NULL);\r
   if (TestPath == NULL) {\r
     return (NULL);\r
   }\r
@@ -1934,8 +1939,9 @@ InternalCommandLineParse (
   //\r
   *CheckPackage = (LIST_ENTRY*)AllocateZeroPool(sizeof(LIST_ENTRY));\r
   if (*CheckPackage == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+    return (EFI_OUT_OF_RESOURCES);\r
   }\r
+\r
   InitializeListHead(*CheckPackage);\r
 \r
   //\r
@@ -1958,9 +1964,17 @@ InternalCommandLineParse (
       // this is a flag\r
       //\r
       CurrentItemPackage = AllocateZeroPool(sizeof(SHELL_PARAM_PACKAGE));\r
-      ASSERT(CurrentItemPackage != NULL);\r
+      if (CurrentItemPackage == NULL) {\r
+        ShellCommandLineFreeVarList(*CheckPackage);\r
+        *CheckPackage = NULL;\r
+        return (EFI_OUT_OF_RESOURCES);\r
+      }\r
       CurrentItemPackage->Name  = AllocateZeroPool(StrSize(Argv[LoopCounter]));\r
-      ASSERT(CurrentItemPackage->Name != NULL);\r
+      if (CurrentItemPackage->Name == NULL) {\r
+        ShellCommandLineFreeVarList(*CheckPackage);\r
+        *CheckPackage = NULL;\r
+        return (EFI_OUT_OF_RESOURCES);\r
+      }\r
       StrCpy(CurrentItemPackage->Name,  Argv[LoopCounter]);\r
       CurrentItemPackage->Type  = CurrentItemType;\r
       CurrentItemPackage->OriginalPosition = (UINTN)(-1);\r
@@ -2024,11 +2038,19 @@ InternalCommandLineParse (
         TempPointer++;\r
       }\r
       CurrentItemPackage = AllocateZeroPool(sizeof(SHELL_PARAM_PACKAGE));\r
-      ASSERT(CurrentItemPackage != NULL);\r
+      if (CurrentItemPackage == NULL) {\r
+        ShellCommandLineFreeVarList(*CheckPackage);\r
+        *CheckPackage = NULL;\r
+        return (EFI_OUT_OF_RESOURCES);\r
+      }\r
       CurrentItemPackage->Name  = NULL;\r
       CurrentItemPackage->Type  = TypePosition;\r
       CurrentItemPackage->Value = AllocateZeroPool(StrSize(TempPointer));\r
-      ASSERT(CurrentItemPackage->Value != NULL);\r
+      if (CurrentItemPackage->Value == NULL) {\r
+        ShellCommandLineFreeVarList(*CheckPackage);\r
+        *CheckPackage = NULL;\r
+        return (EFI_OUT_OF_RESOURCES);\r
+      }\r
       StrCpy(CurrentItemPackage->Value, TempPointer);\r
       CurrentItemPackage->OriginalPosition = Count++;\r
       InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
@@ -2038,8 +2060,9 @@ InternalCommandLineParse (
       //\r
       if (ProblemParam != NULL) {\r
         *ProblemParam = AllocateZeroPool(StrSize(Argv[LoopCounter]));\r
-        ASSERT(*ProblemParam != NULL);\r
-        StrCpy(*ProblemParam, Argv[LoopCounter]);      \r
+        if (*ProblemParam != NULL) {\r
+          StrCpy(*ProblemParam, Argv[LoopCounter]);      \r
+        }\r
       }\r
       ShellCommandLineFreeVarList(*CheckPackage);\r
       *CheckPackage = NULL;\r
@@ -2504,7 +2527,9 @@ ShellCopySearchAndReplace(
     Replace = StrnCatGrow(&Replace, NULL, ReplaceWith, 0);\r
   } else {\r
     Replace = AllocateZeroPool(StrSize(ReplaceWith) + 2*sizeof(CHAR16));\r
-    UnicodeSPrint(Replace, StrSize(ReplaceWith) + 2*sizeof(CHAR16), L"\"%s\"", ReplaceWith);\r
+    if (Replace != NULL) {\r
+      UnicodeSPrint(Replace, StrSize(ReplaceWith) + 2*sizeof(CHAR16), L"\"%s\"", ReplaceWith);\r
+    }\r
   }\r
   if (Replace == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
@@ -3092,11 +3117,9 @@ StrnCatGrow (
       NewSize += 2 * Count * sizeof(CHAR16);\r
     }\r
     *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);\r
-    ASSERT(*Destination != NULL);\r
     *CurrentSize = NewSize;\r
   } else {\r
     *Destination = AllocateZeroPool((Count+1)*sizeof(CHAR16));\r
-    ASSERT(*Destination != NULL);\r
   }\r
 \r
   //\r
@@ -3831,7 +3854,8 @@ ShellIsHexOrDecimalNumber (
   @param[in, out]  Ascii         Boolean value for indicating whether the file is\r
                                  Ascii (TRUE) or UCS2 (FALSE).\r
 \r
-  @return                       The line of text from the file.\r
+  @return                        The line of text from the file.\r
+  @retval NULL                   There was not enough memory available.\r
 \r
   @sa ShellFileHandleReadLine\r
 **/\r
@@ -3852,9 +3876,12 @@ ShellFileHandleReturnLine(
   Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
     RetVal = AllocateZeroPool(Size);\r
+    if (RetVal == NULL) {\r
+      return (NULL);\r
+    }\r
     Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);\r
+    \r
   }\r
-  ASSERT_EFI_ERROR(Status);\r
   if (EFI_ERROR(Status) && (RetVal != NULL)) {\r
     FreePool(RetVal);\r
     RetVal = NULL;\r