]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLib/UefiShellLib.c
ShellPkg: Code refine. Add error handling code to check pointer and remove redundant...
[mirror_edk2.git] / ShellPkg / Library / UefiShellLib / UefiShellLib.c
index 598a2b479a81f29c77ade7464c9727038e065ffc..b7ca41b9846b65bb5c91267b5d91a2a7dbb30f5f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provides interface to shell functionality for shell commands and applications.\r
 \r
-  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2014, 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
@@ -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
@@ -159,7 +163,7 @@ ShellFindSE2 (
 }\r
 \r
 /**\r
-  Function to do most of the work of the constructor.  Allows for calling \r
+  Function to do most of the work of the constructor.  Allows for calling\r
   multiple times without complete re-initialization.\r
 \r
   @param[in] ImageHandle  A copy of the ImageHandle.\r
@@ -417,20 +421,20 @@ ShellGetFileInfo (
 \r
   @param[in]  FileInfo          The information to set.\r
 \r
-  @retval EFI_SUCCESS                  The information was set.\r
+  @retval EFI_SUCCESS           The information was set.\r
   @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.\r
   @retval EFI_UNSUPPORTED       The FileHandle does not support FileInfo.\r
-  @retval EFI_NO_MEDIA               The device has no medium.\r
-  @retval EFI_DEVICE_ERROR         The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
-  @retval EFI_WRITE_PROTECTED    The file or medium is write protected.\r
+  @retval EFI_NO_MEDIA          The device has no medium.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
   @retval EFI_ACCESS_DENIED     The file was opened read only.\r
   @retval EFI_VOLUME_FULL       The volume is full.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 ShellSetFileInfo (\r
-  IN SHELL_FILE_HANDLE                         FileHandle,\r
+  IN SHELL_FILE_HANDLE                    FileHandle,\r
   IN EFI_FILE_INFO              *FileInfo\r
   )\r
 {\r
@@ -443,38 +447,38 @@ ShellSetFileInfo (
   This function opens a file with the open mode according to the file path. The\r
   Attributes is valid only for EFI_FILE_MODE_CREATE.\r
 \r
-  @param  FilePath                 on input the device path to the file.  On output\r
+  @param  FilePath        on input the device path to the file.  On output\r
                           the remaining device path.\r
-  @param  DeviceHandle         pointer to the system device handle.\r
-  @param  FileHandle             pointer to the file handle.\r
-  @param  OpenMode                 the mode to open the file with.\r
-  @param  Attributes             the file's file attributes.\r
-\r
-  @retval EFI_SUCCESS                  The information was set.\r
-  @retval EFI_INVALID_PARAMETER        One of the parameters has an invalid value.\r
-  @retval EFI_UNSUPPORTED            Could not open the file path.\r
-  @retval EFI_NOT_FOUND                The specified file could not be found on the\r
+  @param  DeviceHandle    pointer to the system device handle.\r
+  @param  FileHandle      pointer to the file handle.\r
+  @param  OpenMode        the mode to open the file with.\r
+  @param  Attributes      the file's file attributes.\r
+\r
+  @retval EFI_SUCCESS           The information was set.\r
+  @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
+  @retval EFI_UNSUPPORTED       Could not open the file path.\r
+  @retval EFI_NOT_FOUND         The specified file could not be found on the\r
                                 device or the file system could not be found on\r
                                 the device.\r
-  @retval EFI_NO_MEDIA               The device has no medium.\r
-  @retval EFI_MEDIA_CHANGED        The device has a different medium in it or the\r
+  @retval EFI_NO_MEDIA          The device has no medium.\r
+  @retval EFI_MEDIA_CHANGED     The device has a different medium in it or the\r
                                 medium is no longer supported.\r
-  @retval EFI_DEVICE_ERROR         The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
-  @retval EFI_WRITE_PROTECTED    The file or medium is write protected.\r
-  @retval EFI_ACCESS_DENIED        The file was opened read only.\r
-  @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the\r
+  @retval EFI_DEVICE_ERROR      The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
+  @retval EFI_ACCESS_DENIED     The file was opened read only.\r
+  @retval EFI_OUT_OF_RESOURCES  Not enough resources were available to open the\r
                                 file.\r
-  @retval EFI_VOLUME_FULL            The volume is full.\r
+  @retval EFI_VOLUME_FULL       The volume is full.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 ShellOpenFileByDevicePath(\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL        **FilePath,\r
-  OUT EFI_HANDLE                       *DeviceHandle,\r
+  IN OUT EFI_DEVICE_PATH_PROTOCOL     **FilePath,\r
+  OUT EFI_HANDLE                      *DeviceHandle,\r
   OUT SHELL_FILE_HANDLE               *FileHandle,\r
-  IN UINT64                            OpenMode,\r
-  IN UINT64                            Attributes\r
+  IN UINT64                           OpenMode,\r
+  IN UINT64                           Attributes\r
   )\r
 {\r
   CHAR16                          *FileName;\r
@@ -482,6 +486,8 @@ ShellOpenFileByDevicePath(
   EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol;\r
   EFI_FILE_PROTOCOL               *Handle1;\r
   EFI_FILE_PROTOCOL               *Handle2;\r
+  CHAR16                          *FnafPathName;\r
+  UINTN                           PathLen;\r
 \r
   if (FilePath == NULL || FileHandle == NULL || DeviceHandle == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
@@ -547,13 +553,36 @@ ShellOpenFileByDevicePath(
     Handle2  = Handle1;\r
     Handle1 = NULL;\r
 \r
+    //\r
+    // File Name Alignment Fix (FNAF)\r
+    // Handle2->Open may be incapable of handling a unaligned CHAR16 data.\r
+    // The structure pointed to by FilePath may be not CHAR16 aligned.\r
+    // This code copies the potentially unaligned PathName data from the\r
+    // FilePath structure to the aligned FnafPathName for use in the\r
+    // calls to Handl2->Open.\r
+    //\r
+\r
+    //\r
+    // Determine length of PathName, in bytes.\r
+    //\r
+    PathLen = DevicePathNodeLength (*FilePath) - SIZE_OF_FILEPATH_DEVICE_PATH;\r
+\r
+    //\r
+    // Allocate memory for the aligned copy of the string Extra allocation is to allow for forced alignment\r
+    // Copy bytes from possibly unaligned location to aligned location\r
+    //\r
+    FnafPathName = AllocateCopyPool(PathLen, (UINT8 *)((FILEPATH_DEVICE_PATH*)*FilePath)->PathName);\r
+    if (FnafPathName == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
     //\r
     // Try to test opening an existing file\r
     //\r
     Status = Handle2->Open (\r
                           Handle2,\r
                           &Handle1,\r
-                          ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,\r
+                          FnafPathName,\r
                           OpenMode &~EFI_FILE_MODE_CREATE,\r
                           0\r
                          );\r
@@ -565,11 +594,17 @@ ShellOpenFileByDevicePath(
       Status = Handle2->Open (\r
                             Handle2,\r
                             &Handle1,\r
-                            ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,\r
+                            FnafPathName,\r
                             OpenMode,\r
                             Attributes\r
                            );\r
     }\r
+\r
+    //\r
+    // Free the alignment buffer\r
+    //\r
+    FreePool(FnafPathName);\r
+\r
     //\r
     // Close the last node\r
     //\r
@@ -601,35 +636,35 @@ ShellOpenFileByDevicePath(
 \r
   if FileName is NULL then ASSERT()\r
 \r
-  @param  FileName               pointer to file name\r
-  @param  FileHandle           pointer to the file handle.\r
-  @param  OpenMode               the mode to open the file with.\r
-  @param  Attributes           the file's file attributes.\r
+  @param  FileName      pointer to file name\r
+  @param  FileHandle    pointer to the file handle.\r
+  @param  OpenMode      the mode to open the file with.\r
+  @param  Attributes    the file's file attributes.\r
 \r
-  @retval EFI_SUCCESS                  The information was set.\r
-  @retval EFI_INVALID_PARAMETER        One of the parameters has an invalid value.\r
-  @retval EFI_UNSUPPORTED            Could not open the file path.\r
-  @retval EFI_NOT_FOUND                The specified file could not be found on the\r
+  @retval EFI_SUCCESS           The information was set.\r
+  @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
+  @retval EFI_UNSUPPORTED       Could not open the file path.\r
+  @retval EFI_NOT_FOUND         The specified file could not be found on the\r
                                 device or the file system could not be found\r
                                 on the device.\r
-  @retval EFI_NO_MEDIA               The device has no medium.\r
-  @retval EFI_MEDIA_CHANGED        The device has a different medium in it or the\r
+  @retval EFI_NO_MEDIA          The device has no medium.\r
+  @retval EFI_MEDIA_CHANGED     The device has a different medium in it or the\r
                                 medium is no longer supported.\r
-  @retval EFI_DEVICE_ERROR         The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
-  @retval EFI_WRITE_PROTECTED    The file or medium is write protected.\r
-  @retval EFI_ACCESS_DENIED        The file was opened read only.\r
-  @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the\r
+  @retval EFI_DEVICE_ERROR      The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
+  @retval EFI_ACCESS_DENIED     The file was opened read only.\r
+  @retval EFI_OUT_OF_RESOURCES  Not enough resources were available to open the\r
                                 file.\r
-  @retval EFI_VOLUME_FULL            The volume is full.\r
+  @retval EFI_VOLUME_FULL       The volume is full.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 ShellOpenFileByName(\r
-  IN CONST CHAR16                          *FileName,\r
+  IN CONST CHAR16               *FileName,\r
   OUT SHELL_FILE_HANDLE         *FileHandle,\r
   IN UINT64                     OpenMode,\r
-  IN UINT64                            Attributes\r
+  IN UINT64                     Attributes\r
   )\r
 {\r
   EFI_HANDLE                    DeviceHandle;\r
@@ -688,25 +723,25 @@ ShellOpenFileByName(
   otherwise, the Filehandle is NULL. If the directory already existed, this\r
   function opens the existing directory.\r
 \r
-  @param  DirectoryName                pointer to directory name\r
-  @param  FileHandle             pointer to the file handle.\r
+  @param  DirectoryName   pointer to directory name\r
+  @param  FileHandle      pointer to the file handle.\r
 \r
-  @retval EFI_SUCCESS                  The information was set.\r
-  @retval EFI_INVALID_PARAMETER        One of the parameters has an invalid value.\r
-  @retval EFI_UNSUPPORTED            Could not open the file path.\r
-  @retval EFI_NOT_FOUND                The specified file could not be found on the\r
+  @retval EFI_SUCCESS           The information was set.\r
+  @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
+  @retval EFI_UNSUPPORTED       Could not open the file path.\r
+  @retval EFI_NOT_FOUND         The specified file could not be found on the\r
                                 device or the file system could not be found\r
                                 on the device.\r
-  @retval EFI_NO_MEDIA               The device has no medium.\r
-  @retval EFI_MEDIA_CHANGED        The device has a different medium in it or the\r
+  @retval EFI_NO_MEDIA          The device has no medium.\r
+  @retval EFI_MEDIA_CHANGED     The device has a different medium in it or the\r
                                 medium is no longer supported.\r
-  @retval EFI_DEVICE_ERROR         The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
-  @retval EFI_WRITE_PROTECTED    The file or medium is write protected.\r
-  @retval EFI_ACCESS_DENIED        The file was opened read only.\r
-  @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the\r
+  @retval EFI_DEVICE_ERROR      The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
+  @retval EFI_ACCESS_DENIED     The file was opened read only.\r
+  @retval EFI_OUT_OF_RESOURCES  Not enough resources were available to open the\r
                                 file.\r
-  @retval EFI_VOLUME_FULL            The volume is full.\r
+  @retval EFI_VOLUME_FULL       The volume is full.\r
   @sa ShellOpenFileByName\r
 **/\r
 EFI_STATUS\r
@@ -754,11 +789,11 @@ ShellCreateDirectory(
                                 the number of bytes written.\r
   @param Buffer                 the buffer to put read data into.\r
 \r
-  @retval EFI_SUCCESS            Data was read.\r
-  @retval EFI_NO_MEDIA         The device has no media.\r
-  @retval EFI_DEVICE_ERROR     The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
-  @retval EFI_BUFFER_TO_SMALL  Buffer is too small. ReadSize contains required\r
+  @retval EFI_SUCCESS           Data was read.\r
+  @retval EFI_NO_MEDIA          The device has no media.\r
+  @retval EFI_DEVICE_ERROR  The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required\r
                                 size.\r
 \r
 **/\r
@@ -789,14 +824,14 @@ ShellReadFile(
                               the number of bytes written.\r
   @param Buffer               the buffer containing data to write is stored.\r
 \r
- @retval EFI_SUCCESS           Data was written.\r
- @retval EFI_UNSUPPORTED           Writes to an open directory are not supported.\r
- @retval EFI_NO_MEDIA          The device has no media.\r
- @retval EFI_DEVICE_ERROR          The device reported an error.\r
- @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
- @retval EFI_WRITE_PROTECTED   The device is write-protected.\r
- @retval EFI_ACCESS_DENIED       The file was open for read only.\r
- @retval EFI_VOLUME_FULL           The volume is full.\r
+ @retval EFI_SUCCESS          Data was written.\r
+ @retval EFI_UNSUPPORTED      Writes to an open directory are not supported.\r
+ @retval EFI_NO_MEDIA         The device has no media.\r
+ @retval EFI_DEVICE_ERROR     The device reported an error.\r
+ @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
+ @retval EFI_WRITE_PROTECTED  The device is write-protected.\r
+ @retval EFI_ACCESS_DENIED    The file was open for read only.\r
+ @retval EFI_VOLUME_FULL      The volume is full.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -841,12 +876,12 @@ ShellCloseFile (
   @retval EFI_SUCCESS           the file was closed sucessfully\r
   @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not\r
                                 deleted\r
-  @retval INVALID_PARAMETER            One of the parameters has an invalid value.\r
+  @retval INVALID_PARAMETER     One of the parameters has an invalid value.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 ShellDeleteFile (\r
-  IN SHELL_FILE_HANDLE                         *FileHandle\r
+  IN SHELL_FILE_HANDLE            *FileHandle\r
   )\r
 {\r
   return (FileFunctionMap.DeleteFile(*FileHandle));\r
@@ -874,8 +909,8 @@ ShellDeleteFile (
 EFI_STATUS\r
 EFIAPI\r
 ShellSetFilePosition (\r
-  IN SHELL_FILE_HANDLE                 FileHandle,\r
-  IN UINT64            Position\r
+  IN SHELL_FILE_HANDLE              FileHandle,\r
+  IN UINT64             Position\r
   )\r
 {\r
   return (FileFunctionMap.SetFilePosition(FileHandle, Position));\r
@@ -928,15 +963,19 @@ ShellFlushFile (
   return (FileFunctionMap.FlushFile(FileHandle));\r
 }\r
 \r
-/**\r
-  Retrieves the first file from a directory\r
+/** Retrieve first entry from a directory.\r
+\r
+  This function takes an open directory handle and gets information from the\r
+  first entry in the directory.  A buffer is allocated to contain\r
+  the information and a pointer to the buffer is returned in *Buffer.  The\r
+  caller can use ShellFindNextFile() to get subsequent directory entries.\r
 \r
-  This function opens a directory and gets the first file's info in the\r
-  directory. Caller can use ShellFindNextFile() to get other files.  When\r
-  complete the caller is responsible for calling FreePool() on Buffer.\r
+  The buffer will be freed by ShellFindNextFile() when the last directory\r
+  entry is read.  Otherwise, the caller must free the buffer, using FreePool,\r
+  when finished with it.\r
 \r
-  @param DirHandle              The file handle of the directory to search\r
-  @param Buffer                 Pointer to buffer for file's information\r
+  @param[in]  DirHandle         The file handle of the directory to search.\r
+  @param[out] Buffer            The pointer to the buffer for the file's information.\r
 \r
   @retval EFI_SUCCESS           Found the first file.\r
   @retval EFI_NOT_FOUND         Cannot find the directory.\r
@@ -958,19 +997,18 @@ ShellFindFirstFile (
   //\r
   return (FileHandleFindFirstFile(DirHandle, Buffer));\r
 }\r
-/**\r
-  Retrieves the next file in a directory.\r
+/** Retrieve next entries from a directory.\r
 \r
-  To use this function, caller must call the ShellFindFirstFile() to get the\r
-  first file, and then use this function get other files. This function can be\r
-  called for several times to get each file's information in the directory. If\r
-  the call of ShellFindNextFile() got the last file in the directory, the next\r
-  call of this function has no file to get. *NoFile will be set to TRUE and the\r
-  Buffer memory will be automatically freed.\r
+  To use this function, the caller must first call the ShellFindFirstFile()\r
+  function to get the first directory entry.  Subsequent directory entries are\r
+  retrieved by using the ShellFindNextFile() function.  This function can\r
+  be called several times to get each entry from the directory.  If the call of\r
+  ShellFindNextFile() retrieved the last directory entry, the next call of\r
+  this function will set *NoFile to TRUE and free the buffer.\r
 \r
-  @param DirHandle              the file handle of the directory\r
-  @param Buffer                                    pointer to buffer for file's information\r
-  @param NoFile                                    pointer to boolean when last file is found\r
+  @param[in]  DirHandle         The file handle of the directory.\r
+  @param[out] Buffer            The pointer to buffer for file's information.\r
+  @param[out] NoFile            The pointer to boolean when last file is found.\r
 \r
   @retval EFI_SUCCESS           Found the next file, or reached last file\r
   @retval EFI_NO_MEDIA          The device has no media.\r
@@ -1137,7 +1175,7 @@ ShellSetEnvironmentVariable (
   The CommandLine is executed from the current working directory on the current\r
   device.\r
 \r
-  The EnvironmentVariables and Status parameters are ignored in a pre-UEFI Shell 2.0\r
+  The EnvironmentVariables pararemeter is ignored in a pre-UEFI Shell 2.0\r
   environment.  The values pointed to by the parameters will be unchanged by the\r
   ShellExecute() function.  The Output parameter has no effect in a\r
   UEFI Shell 2.0 environment.\r
@@ -1165,6 +1203,7 @@ ShellExecute (
   OUT EFI_STATUS                *Status OPTIONAL\r
   )\r
 {\r
+  EFI_STATUS                CmdStatus;\r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
@@ -1183,16 +1222,29 @@ ShellExecute (
   //\r
   if (mEfiShellEnvironment2 != NULL) {\r
     //\r
-    // Call EFI Shell version (not using EnvironmentVariables or Status parameters)\r
+    // Call EFI Shell version.\r
     // Due to oddity in the EFI shell we want to dereference the ParentHandle here\r
     //\r
-    return (mEfiShellEnvironment2->Execute(*ParentHandle,\r
+    CmdStatus = (mEfiShellEnvironment2->Execute(*ParentHandle,\r
                                           CommandLine,\r
                                           Output));\r
+    //\r
+    // No Status output parameter so just use the returned status\r
+    //\r
+    if (Status != NULL) {\r
+      *Status = CmdStatus;\r
+    }\r
+    //\r
+    // If there was an error, we can't tell if it was from the command or from\r
+    // the Execute() function, so we'll just assume the shell ran successfully\r
+    // and the error came from the command.\r
+    //\r
+    return EFI_SUCCESS;\r
   }\r
 \r
   return (EFI_UNSUPPORTED);\r
 }\r
+\r
 /**\r
   Retreives the current directory path\r
 \r
@@ -1360,8 +1412,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
@@ -1377,23 +1430,29 @@ InternalShellConvertFileListType (
     //\r
     // allocate new space to copy strings and structure\r
     //\r
-    NewInfo->FullName     = AllocateZeroPool(StrSize(OldInfo->FullName));\r
-    NewInfo->FileName     = AllocateZeroPool(StrSize(OldInfo->FileName));\r
-    NewInfo->Info         = AllocateZeroPool((UINTN)OldInfo->Info->Size);\r
+    NewInfo->FullName     = AllocateCopyPool(StrSize(OldInfo->FullName), OldInfo->FullName);\r
+    NewInfo->FileName     = AllocateCopyPool(StrSize(OldInfo->FileName), OldInfo->FileName);\r
+    NewInfo->Info         = AllocateCopyPool((UINTN)OldInfo->Info->Size, OldInfo->Info);\r
 \r
     //\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
+      //\r
+      // Free the partially allocated new node\r
+      //\r
+      SHELL_FREE_NON_NULL(NewInfo->FullName);\r
+      SHELL_FREE_NON_NULL(NewInfo->FileName);\r
+      SHELL_FREE_NON_NULL(NewInfo->Info);\r
+      SHELL_FREE_NON_NULL(NewInfo);\r
 \r
-    //\r
-    // Copt the strings and structure\r
-    //\r
-    StrCpy(NewInfo->FullName, OldInfo->FullName);\r
-    StrCpy(NewInfo->FileName, OldInfo->FileName);\r
-    gBS->CopyMem (NewInfo->Info, OldInfo->Info, (UINTN)OldInfo->Info->Size);\r
+      //\r
+      // Free the previously converted stuff\r
+      //\r
+      ShellCloseFileMetaArg((EFI_SHELL_FILE_INFO**)(&ListHead));\r
+      ListHead = NULL;\r
+      break;\r
+    }\r
 \r
     //\r
     // add that to the list\r
@@ -1406,8 +1465,8 @@ InternalShellConvertFileListType (
   Opens a group of files based on a path.\r
 \r
   This function uses the Arg to open all the matching files. Each matched\r
-  file has a SHELL_FILE_ARG structure to record the file information. These\r
-  structures are placed on the list ListHead. Users can get the SHELL_FILE_ARG\r
+  file has a SHELL_FILE_INFO structure to record the file information. These\r
+  structures are placed on the list ListHead. Users can get the SHELL_FILE_INFO\r
   structures from ListHead to access each file. This function supports wildcards\r
   and will process '?' and '*' as such.  the list must be freed with a call to\r
   ShellCloseFileMetaArg().\r
@@ -1435,6 +1494,7 @@ ShellOpenFileMetaArg (
 {\r
   EFI_STATUS                    Status;\r
   LIST_ENTRY                    mOldStyleFileList;\r
+  CHAR16                        *CleanFilePathStr;\r
 \r
   //\r
   // ASSERT that Arg and ListHead are not NULL\r
@@ -1442,6 +1502,13 @@ ShellOpenFileMetaArg (
   ASSERT(Arg      != NULL);\r
   ASSERT(ListHead != NULL);\r
 \r
+  CleanFilePathStr = NULL;\r
+\r
+  Status = InternalShellStripQuotes (Arg, &CleanFilePathStr);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
@@ -1449,11 +1516,12 @@ ShellOpenFileMetaArg (
     if (*ListHead == NULL) {\r
       *ListHead = (EFI_SHELL_FILE_INFO*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
       if (*ListHead == NULL) {\r
+        FreePool(CleanFilePathStr);\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
       InitializeListHead(&((*ListHead)->Link));\r
     }\r
-    Status = gEfiShellProtocol->OpenFileList(Arg,\r
+    Status = gEfiShellProtocol->OpenFileList(CleanFilePathStr,\r
                                            OpenMode,\r
                                            ListHead);\r
     if (EFI_ERROR(Status)) {\r
@@ -1463,9 +1531,11 @@ ShellOpenFileMetaArg (
     }\r
     if (*ListHead != NULL && IsListEmpty(&(*ListHead)->Link)) {\r
       FreePool(*ListHead);\r
+      FreePool(CleanFilePathStr);\r
       *ListHead = NULL;\r
       return (EFI_NOT_FOUND);\r
     }\r
+    FreePool(CleanFilePathStr);\r
     return (Status);\r
   }\r
 \r
@@ -1481,15 +1551,17 @@ ShellOpenFileMetaArg (
     //\r
     // Get the EFI Shell list of files\r
     //\r
-    Status = mEfiShellEnvironment2->FileMetaArg(Arg, &mOldStyleFileList);\r
+    Status = mEfiShellEnvironment2->FileMetaArg(CleanFilePathStr, &mOldStyleFileList);\r
     if (EFI_ERROR(Status)) {\r
       *ListHead = NULL;\r
+      FreePool(CleanFilePathStr);\r
       return (Status);\r
     }\r
 \r
     if (*ListHead == NULL) {\r
       *ListHead = (EFI_SHELL_FILE_INFO    *)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
       if (*ListHead == NULL) {\r
+        FreePool(CleanFilePathStr);\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
       InitializeListHead(&((*ListHead)->Link));\r
@@ -1510,9 +1582,11 @@ ShellOpenFileMetaArg (
       *ListHead = NULL;\r
       Status = EFI_NOT_FOUND;\r
     }\r
+    FreePool(CleanFilePathStr);\r
     return (Status);\r
   }\r
 \r
+  FreePool(CleanFilePathStr);\r
   return (EFI_UNSUPPORTED);\r
 }\r
 /**\r
@@ -1557,6 +1631,7 @@ ShellCloseFileMetaArg (
       FreePool(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Info);\r
       FreePool((EFI_SHELL_FILE_INFO_NO_CONST*)Node);\r
     }\r
+    SHELL_FREE_NON_NULL(*ListHead);\r
     return EFI_SUCCESS;\r
   }\r
 \r
@@ -1612,12 +1687,11 @@ 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
-    StrCpy(TestPath, Path);\r
-    StrCat(TestPath, FileName);\r
+    StrnCpy(TestPath, Path, Size/sizeof(CHAR16) - 1);\r
+    StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));\r
     Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);\r
     if (!EFI_ERROR(Status)){\r
       if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {\r
@@ -1649,12 +1723,12 @@ ShellFindFilePath (
           *TempChar = CHAR_NULL;\r
         }\r
         if (TestPath[StrLen(TestPath)-1] != L'\\') {\r
-          StrCat(TestPath, L"\\");\r
+          StrnCat(TestPath, L"\\", Size/sizeof(CHAR16) - 1 - StrLen(TestPath));\r
         }\r
         if (FileName[0] == L'\\') {\r
           FileName++;\r
         }\r
-        StrCat(TestPath, FileName);\r
+        StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));\r
         if (StrStr(Walker, L";") != NULL) {\r
           Walker = StrStr(Walker, L";") + 1;\r
         } else {\r
@@ -1719,14 +1793,13 @@ 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
   for (ExtensionWalker = FileExtension, TempChar2 = (CHAR16*)FileExtension;  TempChar2 != NULL ; ExtensionWalker = TempChar2 + 1){\r
-    StrCpy(TestPath, FileName);\r
+    StrnCpy(TestPath, FileName, Size/sizeof(CHAR16) - 1);\r
     if (ExtensionWalker != NULL) {\r
-      StrCat(TestPath, ExtensionWalker);\r
+      StrnCat(TestPath, ExtensionWalker, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));\r
     }\r
     TempChar = StrStr(TestPath, L";");\r
     if (TempChar != NULL) {\r
@@ -1802,7 +1875,7 @@ InternalIsOnCheckList (
     // If the Type is TypeStart only check the first characters of the passed in param\r
     // If it matches set the type and return TRUE\r
     //\r
-    if (TempListItem->Type == TypeStart) { \r
+    if (TempListItem->Type == TypeStart) {\r
       if (StrnCmp(Name, TempListItem->Name, StrLen(TempListItem->Name)) == 0) {\r
         *Type = TempListItem->Type;\r
         return (TRUE);\r
@@ -1830,6 +1903,7 @@ InternalIsOnCheckList (
 \r
   @param[in] Name               pointer to Name of parameter found\r
   @param[in] AlwaysAllowNumbers TRUE to allow numbers, FALSE to not.\r
+  @param[in] TimeNumbers        TRUE to allow numbers with ":", FALSE otherwise.\r
 \r
   @retval TRUE                  the Parameter is a flag.\r
   @retval FALSE                 the Parameter not a flag.\r
@@ -1838,7 +1912,8 @@ BOOLEAN
 EFIAPI\r
 InternalIsFlag (\r
   IN CONST CHAR16               *Name,\r
-  IN BOOLEAN                    AlwaysAllowNumbers\r
+  IN CONST BOOLEAN              AlwaysAllowNumbers,\r
+  IN CONST BOOLEAN              TimeNumbers\r
   )\r
 {\r
   //\r
@@ -1849,7 +1924,7 @@ InternalIsFlag (
   //\r
   // If we accept numbers then dont return TRUE. (they will be values)\r
   //\r
-  if (((Name[0] == L'-' || Name[0] == L'+') && ShellIsHexaDecimalDigitCharacter(Name[1])) && AlwaysAllowNumbers) {\r
+  if (((Name[0] == L'-' || Name[0] == L'+') && InternalShellIsHexOrDecimalNumber(Name+1, FALSE, FALSE, TimeNumbers)) && AlwaysAllowNumbers) {\r
     return (FALSE);\r
   }\r
 \r
@@ -1909,6 +1984,7 @@ InternalCommandLineParse (
   UINTN                         ValueSize;\r
   UINTN                         Count;\r
   CONST CHAR16                  *TempPointer;\r
+  UINTN                         CurrentValueSize;\r
 \r
   CurrentItemPackage = NULL;\r
   GetItemValue = 0;\r
@@ -1933,6 +2009,10 @@ InternalCommandLineParse (
   // initialize the linked list\r
   //\r
   *CheckPackage = (LIST_ENTRY*)AllocateZeroPool(sizeof(LIST_ENTRY));\r
+  if (*CheckPackage == NULL) {\r
+    return (EFI_OUT_OF_RESOURCES);\r
+  }\r
+\r
   InitializeListHead(*CheckPackage);\r
 \r
   //\r
@@ -1955,10 +2035,17 @@ InternalCommandLineParse (
       // this is a flag\r
       //\r
       CurrentItemPackage = AllocateZeroPool(sizeof(SHELL_PARAM_PACKAGE));\r
-      ASSERT(CurrentItemPackage != NULL);\r
-      CurrentItemPackage->Name  = AllocateZeroPool(StrSize(Argv[LoopCounter]));\r
-      ASSERT(CurrentItemPackage->Name != NULL);\r
-      StrCpy(CurrentItemPackage->Name,  Argv[LoopCounter]);\r
+      if (CurrentItemPackage == NULL) {\r
+        ShellCommandLineFreeVarList(*CheckPackage);\r
+        *CheckPackage = NULL;\r
+        return (EFI_OUT_OF_RESOURCES);\r
+      }\r
+      CurrentItemPackage->Name  = AllocateCopyPool(StrSize(Argv[LoopCounter]), Argv[LoopCounter]);\r
+      if (CurrentItemPackage->Name == NULL) {\r
+        ShellCommandLineFreeVarList(*CheckPackage);\r
+        *CheckPackage = NULL;\r
+        return (EFI_OUT_OF_RESOURCES);\r
+      }\r
       CurrentItemPackage->Type  = CurrentItemType;\r
       CurrentItemPackage->OriginalPosition = (UINTN)(-1);\r
       CurrentItemPackage->Value = NULL;\r
@@ -1971,6 +2058,7 @@ InternalCommandLineParse (
         // possibly trigger the next loop(s) to populate the value of this item\r
         //\r
         case TypeValue:\r
+        case TypeTimeValue:\r
           GetItemValue = 1;\r
           ValueSize = 0;\r
           break;\r
@@ -1990,43 +2078,70 @@ InternalCommandLineParse (
           ASSERT(GetItemValue == 0);\r
           break;\r
       }\r
-    } else if (GetItemValue != 0 && !InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers)) {\r
-      ASSERT(CurrentItemPackage != NULL);\r
+    } else if (GetItemValue != 0 && CurrentItemPackage != NULL && !InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers, (CONST BOOLEAN)(CurrentItemPackage->Type == TypeTimeValue))) {\r
       //\r
       // get the item VALUE for a previous flag\r
       //\r
-      CurrentItemPackage->Value = ReallocatePool(ValueSize, ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16), CurrentItemPackage->Value);\r
-      ASSERT(CurrentItemPackage->Value != NULL);\r
-      if (ValueSize == 0) {\r
-        StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);\r
+      if (StrStr(Argv[LoopCounter], L" ") == NULL) {\r
+        CurrentValueSize = ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16);\r
+        CurrentItemPackage->Value = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value);\r
+        ASSERT(CurrentItemPackage->Value != NULL);\r
+        if (ValueSize == 0) {\r
+          StrnCpy(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1);\r
+        } else {\r
+          StrnCat(CurrentItemPackage->Value, L" ", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));\r
+          StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));\r
+        }\r
+        ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);\r
       } else {\r
-        StrCat(CurrentItemPackage->Value, L" ");\r
-        StrCat(CurrentItemPackage->Value, Argv[LoopCounter]);\r
+        //\r
+        // the parameter has spaces.  must be quoted.\r
+        //\r
+        CurrentValueSize =  ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16) + sizeof(CHAR16) + sizeof(CHAR16);\r
+        CurrentItemPackage->Value = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value);\r
+        ASSERT(CurrentItemPackage->Value != NULL);\r
+        if (ValueSize == 0) {\r
+          StrnCpy(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1);\r
+          StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));\r
+          StrnCat(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));\r
+        } else {\r
+          StrnCat(CurrentItemPackage->Value, L" ", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));\r
+          StrnCat(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));\r
+          StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));\r
+          StrnCat(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));\r
+       }\r
+        ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);\r
       }\r
-      ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);\r
       GetItemValue--;\r
       if (GetItemValue == 0) {\r
         InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
       }\r
-    } else if (!InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers) ){ //|| ProblemParam == NULL) {\r
+    } else if (!InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers, FALSE)){\r
       //\r
       // add this one as a non-flag\r
       //\r
 \r
       TempPointer = Argv[LoopCounter];\r
-      if ((*TempPointer == L'^' && *(TempPointer+1) == L'-') \r
+      if ((*TempPointer == L'^' && *(TempPointer+1) == L'-')\r
        || (*TempPointer == L'^' && *(TempPointer+1) == L'/')\r
        || (*TempPointer == L'^' && *(TempPointer+1) == L'+')\r
       ){\r
         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
-      StrCpy(CurrentItemPackage->Value, TempPointer);\r
+      CurrentItemPackage->Value = AllocateCopyPool(StrSize(TempPointer), TempPointer);\r
+      if (CurrentItemPackage->Value == NULL) {\r
+        ShellCommandLineFreeVarList(*CheckPackage);\r
+        *CheckPackage = NULL;\r
+        return (EFI_OUT_OF_RESOURCES);\r
+      }\r
       CurrentItemPackage->OriginalPosition = Count++;\r
       InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
     } else {\r
@@ -2034,9 +2149,7 @@ InternalCommandLineParse (
       // this was a non-recognised flag... error!\r
       //\r
       if (ProblemParam != NULL) {\r
-        *ProblemParam = AllocateZeroPool(StrSize(Argv[LoopCounter]));\r
-        ASSERT(*ProblemParam != NULL);\r
-        StrCpy(*ProblemParam, Argv[LoopCounter]);      \r
+        *ProblemParam = AllocateCopyPool(StrSize(Argv[LoopCounter]), Argv[LoopCounter]);\r
       }\r
       ShellCommandLineFreeVarList(*CheckPackage);\r
       *CheckPackage = NULL;\r
@@ -2210,14 +2323,9 @@ ShellCommandLineGetFlag (
   CHAR16                        *TempString;\r
 \r
   //\r
-  // ASSERT that both CheckPackage and KeyString aren't NULL\r
-  //\r
-  ASSERT(KeyString != NULL);\r
-\r
+  // return FALSE for no package or KeyString is NULL\r
   //\r
-  // return FALSE for no package\r
-  //\r
-  if (CheckPackage == NULL) {\r
+  if (CheckPackage == NULL || KeyString == NULL) {\r
     return (FALSE);\r
   }\r
 \r
@@ -2279,9 +2387,9 @@ ShellCommandLineGetValue (
   CHAR16                        *TempString;\r
 \r
   //\r
-  // check for CheckPackage == NULL\r
+  // return NULL for no package or KeyString is NULL\r
   //\r
-  if (CheckPackage == NULL) {\r
+  if (CheckPackage == NULL || KeyString == NULL) {\r
     return (NULL);\r
   }\r
 \r
@@ -2501,12 +2609,14 @@ 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
   }\r
-  NewString = SetMem16(NewString, NewSize, CHAR_NULL);\r
+  NewString = ZeroMem(NewString, NewSize);\r
   while (*SourceString != CHAR_NULL) {\r
     //\r
     // if we find the FindTarget and either Skip == FALSE or Skip  and we\r
@@ -2521,7 +2631,7 @@ ShellCopySearchAndReplace(
         FreePool(Replace);\r
         return (EFI_BUFFER_TOO_SMALL);\r
       }\r
-      StrCat(NewString, Replace);\r
+      StrnCat(NewString, Replace, NewSize/sizeof(CHAR16) - 1 - StrLen(NewString));\r
     } else {\r
       Size = StrSize(NewString);\r
       if (Size + sizeof(CHAR16) > NewSize) {\r
@@ -2561,10 +2671,12 @@ InternalPrintTo (
     return (gEfiShellProtocol->WriteFile(gEfiShellParametersProtocol->StdOut, &Size, (VOID*)String));\r
   }\r
   if (mEfiShellInterface          != NULL) {\r
+    if (mEfiShellInterface->RedirArgc == 0) { \r
     //\r
     // Divide in half for old shell.  Must be string length not size.\r
-    //\r
-    Size /= 2;\r
+      // \r
+      Size /=2;  // Divide in half only when no redirection.\r
+    }\r
     return (mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut,          &Size, (VOID*)String));\r
   }\r
   ASSERT(FALSE);\r
@@ -2675,6 +2787,11 @@ InternalShellPrintWorker(
     //\r
     if (ResumeLocation != NULL) {\r
       if (*(ResumeLocation-1) == L'^') {\r
+        //\r
+        // Move cursor back 1 position to overwrite the ^\r
+        //\r
+        gST->ConOut->SetCursorPosition(gST->ConOut, gST->ConOut->Mode->CursorColumn - 1, gST->ConOut->Mode->CursorRow);\r
+\r
         //\r
         // Print a simple '%' symbol\r
         //\r
@@ -2842,9 +2959,10 @@ ShellPrintHiiEx(
 \r
   @param[in] DirName      Path to directory to test.\r
 \r
-  @retval EFI_SUCCESS     The Path represents a directory\r
-  @retval EFI_NOT_FOUND   The Path does not represent a directory\r
-  @return other           The path failed to open\r
+  @retval EFI_SUCCESS             The Path represents a directory\r
+  @retval EFI_NOT_FOUND           The Path does not represent a directory\r
+  @retval EFI_OUT_OF_RESOURCES    A memory allocation failed.\r
+  @return                         The path failed to open\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -2869,6 +2987,10 @@ ShellIsDirectory(
     //\r
     if (gEfiShellProtocol != NULL) {\r
       TempLocation  = StrnCatGrow(&TempLocation, NULL, DirName, 0);\r
+      if (TempLocation == NULL) {\r
+        ShellCloseFile(&Handle);\r
+        return (EFI_OUT_OF_RESOURCES);\r
+      }\r
       TempLocation2 = StrStr(TempLocation, L":");\r
       if (TempLocation2 != NULL && StrLen(StrStr(TempLocation, L":")) == 2) {\r
         *(TempLocation2+1) = CHAR_NULL;\r
@@ -2968,9 +3090,35 @@ ShellIsFileInPath(
   return (Status);\r
 }\r
 \r
+/**\r
+  Function return the number converted from a hex representation of a number.\r
+\r
+  Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid\r
+  result.  Use ShellConvertStringToUint64 instead.\r
+\r
+  @param[in] String   String representation of a number.\r
+\r
+  @return             The unsigned integer result of the conversion.\r
+  @retval (UINTN)(-1) An error occured.\r
+**/\r
+UINTN\r
+EFIAPI\r
+ShellHexStrToUintn(\r
+  IN CONST CHAR16 *String\r
+  )\r
+{\r
+  UINT64        RetVal;\r
+\r
+  if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, TRUE, TRUE))) {\r
+    return ((UINTN)RetVal);\r
+  }\r
+  \r
+  return ((UINTN)(-1));\r
+}\r
+\r
 /**\r
   Function to determine whether a string is decimal or hex representation of a number\r
-  and return the number converted from the string.\r
+  and return the number converted from the string.  Spaces are always skipped.\r
 \r
   @param[in] String   String representation of a number\r
 \r
@@ -2988,7 +3136,7 @@ ShellStrToUintn(
 \r
   Hex = FALSE;\r
 \r
-  if (!InternalShellIsHexOrDecimalNumber(String, Hex, TRUE)) {\r
+  if (!InternalShellIsHexOrDecimalNumber(String, Hex, TRUE, FALSE)) {\r
     Hex = TRUE;\r
   }\r
 \r
@@ -3085,15 +3233,15 @@ StrnCatGrow (
   //\r
   if (CurrentSize != NULL) {\r
     NewSize = *CurrentSize;\r
-    while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) {\r
-      NewSize += 2 * Count * sizeof(CHAR16);\r
+    if (NewSize < DestinationStartSize + (Count * sizeof(CHAR16))) {\r
+      while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) {\r
+        NewSize += 2 * Count * sizeof(CHAR16);\r
+      }\r
+      *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);\r
+      *CurrentSize = NewSize;\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
@@ -3165,7 +3313,9 @@ ShellPromptForResponse (
       //\r
       gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
       Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-      ASSERT_EFI_ERROR(Status);\r
+      if (EFI_ERROR(Status)) {\r
+        break;\r
+      }\r
       ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
       if (Key.UnicodeChar == L'Q' || Key.UnicodeChar ==L'q') {\r
         *Resp = ShellPromptResponseQuit;\r
@@ -3182,9 +3332,15 @@ ShellPromptForResponse (
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
+        if (ShellGetExecutionBreakFlag()) {\r
+          Status = EFI_ABORTED;\r
+          break;\r
+        }\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-        ASSERT_EFI_ERROR(Status);\r
+        if (EFI_ERROR(Status)) {\r
+          break;\r
+        }\r
         ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
         switch (Key.UnicodeChar) {\r
           case L'Y':\r
@@ -3210,9 +3366,15 @@ ShellPromptForResponse (
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
+        if (ShellGetExecutionBreakFlag()) {\r
+          Status = EFI_ABORTED;\r
+          break;\r
+        }\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-        ASSERT_EFI_ERROR(Status);\r
+        if (EFI_ERROR(Status)) {\r
+          break;\r
+        }\r
         ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
         switch (Key.UnicodeChar) {\r
           case L'Y':\r
@@ -3244,10 +3406,16 @@ ShellPromptForResponse (
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
+        if (ShellGetExecutionBreakFlag()) {\r
+          Status = EFI_ABORTED;\r
+          break;\r
+        }\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         if (Type == ShellPromptResponseTypeEnterContinue) {\r
           Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-          ASSERT_EFI_ERROR(Status);\r
+          if (EFI_ERROR(Status)) {\r
+            break;\r
+          }\r
           ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
           if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
             *Resp = ShellPromptResponseContinue;\r
@@ -3271,9 +3439,15 @@ ShellPromptForResponse (
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
+        if (ShellGetExecutionBreakFlag()) {\r
+          Status = EFI_ABORTED;\r
+          break;\r
+        }\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-        ASSERT_EFI_ERROR(Status);\r
+        if (EFI_ERROR(Status)) {\r
+          break;\r
+        }\r
         ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
         switch (Key.UnicodeChar) {\r
           case L'Y':\r
@@ -3292,9 +3466,15 @@ ShellPromptForResponse (
         ShellPrintEx(-1, -1, L"%s", Prompt);\r
       }\r
       while(1) {\r
+        if (ShellGetExecutionBreakFlag()) {\r
+          Status = EFI_ABORTED;\r
+          break;\r
+        }\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-        ASSERT_EFI_ERROR(Status);\r
+        if (EFI_ERROR(Status)) {\r
+          break;\r
+        }\r
         ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
         if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
           break;\r
@@ -3305,6 +3485,7 @@ ShellPromptForResponse (
       break;\r
     //\r
     // This is the location to add new prompt types.\r
+    // If your new type loops remember to add ExecutionBreak support.\r
     //\r
     default:\r
       ASSERT(FALSE);\r
@@ -3372,6 +3553,7 @@ ShellPromptForResponseHii (
   @param[in] String       The string to evaluate.\r
   @param[in] ForceHex     TRUE - always assume hex.\r
   @param[in] StopAtSpace  TRUE to halt upon finding a space, FALSE to keep going.\r
+  @param[in] TimeNumbers        TRUE to allow numbers with ":", FALSE otherwise.\r
 \r
   @retval TRUE        It is all numeric (dec/hex) characters.\r
   @retval FALSE       There is a non-numeric character.\r
@@ -3381,7 +3563,8 @@ EFIAPI
 InternalShellIsHexOrDecimalNumber (\r
   IN CONST CHAR16   *String,\r
   IN CONST BOOLEAN  ForceHex,\r
-  IN CONST BOOLEAN  StopAtSpace\r
+  IN CONST BOOLEAN  StopAtSpace,\r
+  IN CONST BOOLEAN  TimeNumbers\r
   )\r
 {\r
   BOOLEAN Hex;\r
@@ -3392,7 +3575,7 @@ InternalShellIsHexOrDecimalNumber (
   if (String != NULL && *String == L'-') {\r
     String++;\r
   }\r
-  \r
+\r
   if (String == NULL) {\r
     return (FALSE);\r
   }\r
@@ -3425,6 +3608,9 @@ InternalShellIsHexOrDecimalNumber (
   // loop through the remaining characters and use the lib function\r
   //\r
   for ( ; String != NULL && *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){\r
+    if (TimeNumbers && (String[0] == L':')) {\r
+      continue;\r
+    }\r
     if (Hex) {\r
       if (!ShellIsHexaDecimalDigitCharacter(*String)) {\r
         return (FALSE);\r
@@ -3471,7 +3657,7 @@ ShellFileExists(
 }\r
 \r
 /**\r
-  Convert a Unicode character to upper case only if \r
+  Convert a Unicode character to upper case only if\r
   it maps to a valid small-case ASCII character.\r
 \r
   This internal function only deal with Unicode character\r
@@ -3503,7 +3689,7 @@ InternalShellCharToUpper (
 \r
   This internal function only deal with Unicode character\r
   which maps to a valid hexadecimal ASII character, i.e.\r
-  L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other \r
+  L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other\r
   Unicode character, the value returned does not make sense.\r
 \r
   @param  Char  The character to convert.\r
@@ -3567,9 +3753,9 @@ InternalShellStrHexToUint64 (
   if (String == NULL || StrSize(String) == 0 || Value == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
-  \r
+\r
   //\r
-  // Ignore the pad spaces (space or tab) \r
+  // Ignore the pad spaces (space or tab)\r
   //\r
   while ((*String == L' ') || (*String == L'\t')) {\r
     String++;\r
@@ -3593,17 +3779,17 @@ InternalShellStrHexToUint64 (
   }\r
 \r
   Result = 0;\r
-  \r
+\r
   //\r
   // Skip spaces if requested\r
   //\r
   while (StopAtSpace && *String == L' ') {\r
     String++;\r
   }\r
-  \r
+\r
   while (ShellIsHexaDecimalDigitCharacter (*String)) {\r
     //\r
-    // If the Hex Number represented by String overflows according \r
+    // If the Hex Number represented by String overflows according\r
     // to the range defined by UINTN, then ASSERT().\r
     //\r
     if (!(Result <= (RShiftU64((((UINT64) ~0) - InternalShellHexCharToUintn (*String)), 4)))) {\r
@@ -3616,10 +3802,10 @@ InternalShellStrHexToUint64 (
     String++;\r
 \r
     //\r
-    // Skip spaces if requested\r
+    // stop at spaces if requested\r
     //\r
-    while (StopAtSpace && *String == L' ') {\r
-      String++;\r
+    if (StopAtSpace && *String == L' ') {\r
+      break;\r
     }\r
   }\r
 \r
@@ -3694,10 +3880,10 @@ InternalShellStrDecimalToUint64 (
   }\r
   while (ShellIsDecimalDigitCharacter (*String)) {\r
     //\r
-    // If the number represented by String overflows according \r
+    // If the number represented by String overflows according\r
     // to the range defined by UINT64, then ASSERT().\r
     //\r
-    \r
+\r
     if (!(Result <= (DivU64x32((((UINT64) ~0) - (*String - L'0')),10)))) {\r
       return (EFI_DEVICE_ERROR);\r
     }\r
@@ -3714,7 +3900,7 @@ InternalShellStrDecimalToUint64 (
   }\r
 \r
   *Value = Result;\r
-  \r
+\r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -3727,7 +3913,7 @@ InternalShellStrDecimalToUint64 (
   @param[out] Value       Upon a successful return the value of the conversion.\r
   @param[in] ForceHex     TRUE - always assume hex.\r
   @param[in] StopAtSpace  FALSE to skip spaces.\r
-  \r
+\r
   @retval EFI_SUCCESS             The conversion was successful.\r
   @retval EFI_INVALID_PARAMETER   String contained an invalid character.\r
   @retval EFI_NOT_FOUND           String was a number, but Value was NULL.\r
@@ -3748,10 +3934,10 @@ ShellConvertStringToUint64(
 \r
   Hex = ForceHex;\r
 \r
-  if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace)) {\r
+  if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace, FALSE)) {\r
     if (!Hex) {\r
       Hex = TRUE;\r
-      if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace)) {\r
+      if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace, FALSE)) {\r
         return (EFI_INVALID_PARAMETER);\r
       }\r
     } else {\r
@@ -3767,9 +3953,9 @@ ShellConvertStringToUint64(
   //\r
   // make sure we have something left that is numeric.\r
   //\r
-  if (Walker == NULL || *Walker == CHAR_NULL || !InternalShellIsHexOrDecimalNumber(Walker, Hex, StopAtSpace)) {\r
+  if (Walker == NULL || *Walker == CHAR_NULL || !InternalShellIsHexOrDecimalNumber(Walker, Hex, StopAtSpace, FALSE)) {\r
     return (EFI_INVALID_PARAMETER);\r
-  } \r
+  }\r
 \r
   //\r
   // do the conversion.\r
@@ -3828,7 +4014,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
@@ -3849,9 +4036,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
@@ -3967,3 +4157,146 @@ ShellFileHandleReadLine(
 \r
   return (Status);\r
 }\r
+\r
+/**\r
+  Function to print help file / man page content in the spec from the UEFI Shell protocol GetHelpText function.\r
+\r
+  @param[in] CommandToGetHelpOn  Pointer to a string containing the command name of help file to be printed.\r
+  @param[in] SectionToGetHelpOn  Pointer to the section specifier(s).\r
+  @param[in] PrintCommandText    If TRUE, prints the command followed by the help content, otherwise prints \r
+                                 the help content only.\r
+  @retval EFI_DEVICE_ERROR       The help data format was incorrect.\r
+  @retval EFI_NOT_FOUND          The help data could not be found.\r
+  @retval EFI_SUCCESS            The operation was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellPrintHelp (\r
+  IN CONST CHAR16     *CommandToGetHelpOn,\r
+  IN CONST CHAR16     *SectionToGetHelpOn,\r
+  IN BOOLEAN          PrintCommandText\r
+  )\r
+{\r
+       EFI_STATUS          Status;\r
+       CHAR16              *OutText;\r
+         \r
+       OutText = NULL;\r
+       \r
+  //\r
+  // Get the string to print based\r
+  //\r
+       Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText);\r
+  \r
+  //\r
+  // make sure we got a valid string\r
+  //\r
+  if (EFI_ERROR(Status)){\r
+    return Status;\r
+       } \r
+  if (OutText == NULL || StrLen(OutText) == 0) {\r
+    return EFI_NOT_FOUND;  \r
+       }\r
+  \r
+  //\r
+  // Chop off trailing stuff we dont need\r
+  //\r
+  while (OutText[StrLen(OutText)-1] == L'\r' || OutText[StrLen(OutText)-1] == L'\n' || OutText[StrLen(OutText)-1] == L' ') {\r
+    OutText[StrLen(OutText)-1] = CHAR_NULL;\r
+  }\r
+  \r
+  //\r
+  // Print this out to the console\r
+  //\r
+  if (PrintCommandText) {\r
+    ShellPrintEx(-1, -1, L"%H%-14s%N- %s\r\n", CommandToGetHelpOn, OutText);\r
+  } else {\r
+    ShellPrintEx(-1, -1, L"%N%s\r\n", OutText);\r
+  }\r
+  \r
+  SHELL_FREE_NON_NULL(OutText);\r
+\r
+       return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Function to delete a file by name\r
+  \r
+  @param[in]       FileName       Pointer to file name to delete.\r
+  \r
+  @retval EFI_SUCCESS             the file was deleted sucessfully\r
+  @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not\r
+                                  deleted\r
+  @retval EFI_INVALID_PARAMETER   One of the parameters has an invalid value.\r
+  @retval EFI_NOT_FOUND           The specified file could not be found on the\r
+                                  device or the file system could not be found\r
+                                  on the device.\r
+  @retval EFI_NO_MEDIA            The device has no medium.\r
+  @retval EFI_MEDIA_CHANGED       The device has a different medium in it or the\r
+                                  medium is no longer supported.\r
+  @retval EFI_DEVICE_ERROR        The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED    The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED     The file or medium is write protected.\r
+  @retval EFI_ACCESS_DENIED       The file was opened read only.\r
+  @retval EFI_OUT_OF_RESOURCES    Not enough resources were available to open the\r
+                                  file.\r
+  @retval other                   The file failed to open\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellDeleteFileByName(\r
+  IN CONST CHAR16               *FileName\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  SHELL_FILE_HANDLE         FileHandle;\r
+  \r
+  Status = ShellFileExists(FileName);\r
+  \r
+  if (Status == EFI_SUCCESS){\r
+    Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0x0);\r
+    if (Status == EFI_SUCCESS){\r
+      Status = ShellDeleteFile(&FileHandle);\r
+    }\r
+  } \r
+\r
+  return(Status);\r
+  \r
+}\r
+\r
+/**\r
+  Cleans off all the quotes in the string.\r
+\r
+  @param[in]     OriginalString   pointer to the string to be cleaned.\r
+  @param[out]   CleanString      The new string with all quotes removed. \r
+                                                  Memory allocated in the function and free \r
+                                                  by caller.\r
+\r
+  @retval EFI_SUCCESS   The operation was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InternalShellStripQuotes (\r
+  IN  CONST CHAR16     *OriginalString,\r
+  OUT CHAR16           **CleanString\r
+  )\r
+{\r
+  CHAR16            *Walker;\r
+  \r
+  if (OriginalString == NULL || CleanString == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *CleanString = AllocateCopyPool (StrSize (OriginalString), OriginalString);\r
+  if (*CleanString == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  for (Walker = *CleanString; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {\r
+    if (*Walker == L'\"') {\r
+      CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r