]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ShellProtocol.c
ShellPkg: Make Argv[0] the full file path of the command
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellProtocol.c
index e42f081834de528d600b67725854bd1716fb2299..502713770501158cf80c12e596f6a5bc2b4eef38 100644 (file)
@@ -2,7 +2,7 @@
   Member functions of EFI_SHELL_PROTOCOL and functions for creation,\r
   manipulation, and initialization of EFI_SHELL_PROTOCOL.\r
 \r
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 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
@@ -14,7 +14,6 @@
 **/\r
 \r
 #include "Shell.h"\r
-#include <Library/FileHandleLib.h>\r
 \r
 /**\r
   Close an open file handle.\r
@@ -116,27 +115,19 @@ InternalShellProtocolDebugPrintMessage (
   IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
   )\r
 {\r
-  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *DevicePathToText;\r
   EFI_STATUS                        Status;\r
   CHAR16                            *Temp;\r
 \r
   Status = EFI_SUCCESS;\r
   DEBUG_CODE_BEGIN();\r
-  DevicePathToText = NULL;\r
 \r
-  Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid,\r
-                               NULL,\r
-                               (VOID**)&DevicePathToText);\r
   if (Mapping != NULL) {\r
     DEBUG((EFI_D_INFO, "Added new map item:\"%S\"\r\n", Mapping));\r
   }\r
-  if (!EFI_ERROR(Status)) {\r
-    if (DevicePath != NULL) {\r
-      Temp = DevicePathToText->ConvertDevicePathToText(DevicePath, TRUE, TRUE);\r
-      DEBUG((EFI_D_INFO, "DevicePath: %S\r\n", Temp));\r
-      FreePool(Temp);\r
-    }\r
-  }\r
+  Temp = ConvertDevicePathToText(DevicePath, TRUE, TRUE);\r
+  DEBUG((EFI_D_INFO, "DevicePath: %S\r\n", Temp));\r
+  FreePool(Temp);\r
+\r
   DEBUG_CODE_END();\r
   return (Status);\r
 }\r
@@ -467,9 +458,20 @@ EfiShellGetFilePathFromDevicePath(
           // append the path part onto the filepath.\r
           //\r
           ASSERT((PathForReturn == NULL && PathSize == 0) || (PathForReturn != NULL));\r
-          PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, L"\\", 1);\r
 \r
           AlignedNode = AllocateCopyPool (DevicePathNodeLength(FilePath), FilePath);\r
+\r
+          // File Path Device Path Nodes 'can optionally add a "\" separator to\r
+          //  the beginning and/or the end of the Path Name string.'\r
+          // (UEFI Spec 2.4 section 9.3.6.4).\r
+          // If necessary, add a "\", but otherwise don't\r
+          // (This is specified in the above section, and also implied by the\r
+          //  UEFI Shell spec section 3.7)\r
+          if ((PathForReturn[PathSize - 1] != L'\\') &&\r
+              (AlignedNode->PathName[0]    != L'\\')) {\r
+            PathForReturn = StrnCatGrow (&PathForReturn, &PathSize, L"\\", 1);\r
+          }\r
+\r
           PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, AlignedNode->PathName, 0);\r
           FreePool(AlignedNode);\r
         }\r
@@ -488,10 +490,12 @@ EfiShellGetFilePathFromDevicePath(
   This function converts a file system style name to a device path, by replacing any\r
   mapping references to the associated device path.\r
 \r
-  @param Path                   the pointer to the path\r
+  @param[in] Path               The pointer to the path.\r
 \r
-  @return all                   The pointer of the file path. The file path is callee\r
+  @return                       The pointer of the file path. The file path is callee\r
                                 allocated and should be freed by the caller.\r
+  @retval NULL                  The path could not be found.\r
+  @retval NULL                  There was not enough available memory.\r
 **/\r
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
@@ -525,7 +529,9 @@ EfiShellGetDevicePathFromFilePath(
     Size = StrSize(Cwd);\r
     Size += StrSize(Path);\r
     NewPath = AllocateZeroPool(Size);\r
-    ASSERT(NewPath != NULL);\r
+    if (NewPath == NULL) {\r
+      return (NULL);\r
+    }\r
     StrCpy(NewPath, Cwd);\r
     if (*Path == L'\\') {\r
       Path++;\r
@@ -543,8 +549,7 @@ EfiShellGetDevicePathFromFilePath(
   //\r
   ASSERT((MapName == NULL && Size == 0) || (MapName != NULL));\r
   MapName = StrnCatGrow(&MapName, &Size, Path, (StrStr(Path, L":")-Path+1));\r
-  if (MapName[StrLen(MapName)-1] != L':') {\r
-    ASSERT(FALSE);\r
+  if (MapName == NULL || MapName[StrLen(MapName)-1] != L':') {\r
     return (NULL);\r
   }\r
 \r
@@ -564,7 +569,6 @@ EfiShellGetDevicePathFromFilePath(
   //\r
   DevicePathCopyForFree = DevicePathCopy = DuplicateDevicePath(DevicePath);\r
   if (DevicePathCopy == NULL) {\r
-    ASSERT(FALSE);\r
     FreePool(MapName);\r
     return (NULL);\r
   }\r
@@ -588,7 +592,7 @@ EfiShellGetDevicePathFromFilePath(
   if (*(Path+StrLen(MapName)+1) == CHAR_NULL) {\r
     DevicePathForReturn = FileDevicePath(Handle, L"\\");\r
   } else {\r
-    DevicePathForReturn = FileDevicePath(Handle, Path+StrLen(MapName)+1);\r
+    DevicePathForReturn = FileDevicePath(Handle, Path+StrLen(MapName));\r
   }\r
 \r
   FreePool(MapName);\r
@@ -646,15 +650,12 @@ EfiShellGetDeviceName(
 {\r
   EFI_STATUS                        Status;\r
   EFI_COMPONENT_NAME2_PROTOCOL      *CompName2;\r
-  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *DevicePathToText;\r
   EFI_DEVICE_PATH_PROTOCOL          *DevicePath;\r
   EFI_HANDLE                        *HandleList;\r
   UINTN                             HandleCount;\r
   UINTN                             LoopVar;\r
   CHAR16                            *DeviceNameToReturn;\r
   CHAR8                             *Lang;\r
-  CHAR8                             *TempChar;\r
-\r
   UINTN                             ParentControllerCount;\r
   EFI_HANDLE                        *ParentControllerBuffer;\r
   UINTN                             ParentDriverCount;\r
@@ -711,23 +712,7 @@ EfiShellGetDeviceName(
       if (EFI_ERROR(Status)) {\r
         continue;\r
       }\r
-      if (Language == NULL) {\r
-        Lang = AllocateZeroPool(AsciiStrSize(CompName2->SupportedLanguages));\r
-        if (Lang == NULL) {\r
-          return (EFI_OUT_OF_RESOURCES);\r
-        }\r
-        AsciiStrCpy(Lang, CompName2->SupportedLanguages);\r
-        TempChar = AsciiStrStr(Lang, ";");\r
-        if (TempChar != NULL){\r
-          *TempChar = CHAR_NULL;\r
-        }\r
-      } else {\r
-        Lang = AllocateZeroPool(AsciiStrSize(Language));\r
-        if (Lang == NULL) {\r
-          return (EFI_OUT_OF_RESOURCES);\r
-        }\r
-        AsciiStrCpy(Lang, Language);\r
-      }\r
+      Lang = GetBestLanguageForDriver(CompName2->SupportedLanguages, Language, FALSE);\r
       Status = CompName2->GetControllerName(CompName2, DeviceHandle, NULL, Lang, &DeviceNameToReturn);\r
       FreePool(Lang);\r
       Lang = NULL;\r
@@ -770,23 +755,7 @@ EfiShellGetDeviceName(
           if (EFI_ERROR(Status)) {\r
             continue;\r
           }\r
-          if (Language == NULL) {\r
-            Lang = AllocateZeroPool(AsciiStrSize(CompName2->SupportedLanguages));\r
-            if (Lang == NULL) {\r
-              return (EFI_OUT_OF_RESOURCES);\r
-            }\r
-            AsciiStrCpy(Lang, CompName2->SupportedLanguages);\r
-            TempChar = AsciiStrStr(Lang, ";");\r
-            if (TempChar != NULL){\r
-              *TempChar = CHAR_NULL;\r
-            }\r
-          } else {\r
-            Lang = AllocateZeroPool(AsciiStrSize(Language));\r
-            if (Lang == NULL) {\r
-              return (EFI_OUT_OF_RESOURCES);\r
-            }\r
-            AsciiStrCpy(Lang, Language);\r
-          }\r
+          Lang = GetBestLanguageForDriver(CompName2->SupportedLanguages, Language, FALSE);\r
           Status = CompName2->GetControllerName(CompName2, ParentControllerBuffer[LoopVar], DeviceHandle, Lang, &DeviceNameToReturn);\r
           FreePool(Lang);\r
           Lang = NULL;\r
@@ -814,28 +783,19 @@ EfiShellGetDeviceName(
     }\r
   }\r
   if ((Flags & EFI_DEVICE_NAME_USE_DEVICE_PATH) != 0) {\r
-    Status = gBS->LocateProtocol(\r
-      &gEfiDevicePathToTextProtocolGuid,\r
+    Status = gBS->OpenProtocol(\r
+      DeviceHandle,\r
+      &gEfiDevicePathProtocolGuid,\r
+      (VOID**)&DevicePath,\r
+      gImageHandle,\r
       NULL,\r
-      (VOID**)&DevicePathToText);\r
-    //\r
-    // we now have the device path to text protocol\r
-    //\r
+      EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
     if (!EFI_ERROR(Status)) {\r
-      Status = gBS->OpenProtocol(\r
-        DeviceHandle,\r
-        &gEfiDevicePathProtocolGuid,\r
-        (VOID**)&DevicePath,\r
-        gImageHandle,\r
-        NULL,\r
-        EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
-      if (!EFI_ERROR(Status)) {\r
-        //\r
-        // use device path to text on the device path\r
-        //\r
-        *BestDeviceName = DevicePathToText->ConvertDevicePathToText(DevicePath, TRUE, TRUE);\r
-        return (EFI_SUCCESS);\r
-      }\r
+      //\r
+      // use device path to text on the device path\r
+      //\r
+      *BestDeviceName = ConvertDevicePathToText(DevicePath, TRUE, TRUE);\r
+      return (EFI_SUCCESS);\r
     }\r
   }\r
   //\r
@@ -993,7 +953,6 @@ InternalOpenFileDevicePath(
   SHELL_FILE_HANDLE               ShellHandle;\r
   EFI_FILE_PROTOCOL               *Handle1;\r
   EFI_FILE_PROTOCOL               *Handle2;\r
-  EFI_DEVICE_PATH_PROTOCOL        *DpCopy;\r
   FILEPATH_DEVICE_PATH            *AlignedNode;\r
 \r
   if (FileHandle == NULL) {\r
@@ -1003,7 +962,6 @@ InternalOpenFileDevicePath(
   Handle1       = NULL;\r
   Handle2       = NULL;\r
   Handle        = NULL;\r
-  DpCopy        = DevicePath;\r
   ShellHandle   = NULL;\r
   FilePathNode  = NULL;\r
   AlignedNode   = NULL;\r
@@ -1409,7 +1367,9 @@ EfiShellEnablePageBreak (
                             variables with the format 'x=y', where x is the\r
                             environment variable name and y is the value. If this\r
                             is NULL, then the current shell environment is used.\r
-  @param StatusCode         Points to the status code returned by the command.\r
+\r
+  @param[out] ExitDataSize  ExitDataSize as returned from gBS->StartImage\r
+  @param[out] ExitData      ExitData as returned from gBS->StartImage\r
 \r
   @retval EFI_SUCCESS       The command executed successfully. The  status code\r
                             returned by the command is pointed to by StatusCode.\r
@@ -1424,14 +1384,27 @@ InternalShellExecuteDevicePath(
   IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
   IN CONST CHAR16                   *CommandLine OPTIONAL,\r
   IN CONST CHAR16                   **Environment OPTIONAL,\r
-  OUT EFI_STATUS                    *StatusCode OPTIONAL\r
+  OUT UINTN                         *ExitDataSize OPTIONAL,\r
+  OUT CHAR16                        **ExitData OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                    Status;\r
+  EFI_STATUS                    CleanupStatus;\r
   EFI_HANDLE                    NewHandle;\r
   EFI_LOADED_IMAGE_PROTOCOL     *LoadedImage;\r
   LIST_ENTRY                    OrigEnvs;\r
   EFI_SHELL_PARAMETERS_PROTOCOL ShellParamsProtocol;\r
+  UINTN                         InternalExitDataSize;\r
+  UINTN                         *ExitDataSizePtr;\r
+  CHAR16                        *ImagePath;\r
+\r
+  // ExitDataSize is not OPTIONAL for gBS->BootServices, provide somewhere for\r
+  // it to be dumped if the caller doesn't want it.\r
+  if (ExitData == NULL) {\r
+    ExitDataSizePtr = &InternalExitDataSize;\r
+  } else {\r
+    ExitDataSizePtr = ExitDataSize;\r
+  }\r
 \r
   if (ParentImageHandle == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
@@ -1492,38 +1465,76 @@ InternalShellExecuteDevicePath(
     ShellParamsProtocol.StdErr  = ShellInfoObject.NewShellParametersProtocol->StdErr;\r
     Status = UpdateArgcArgv(&ShellParamsProtocol, CommandLine, NULL, NULL);\r
     ASSERT_EFI_ERROR(Status);\r
+    //\r
+    // Replace Argv[0] with the full path of the binary we're executing:\r
+    // If the command line was "foo", the binary might be called "foo.efi".\r
+    // "The first entry in [Argv] is always the full file path of the\r
+    //  executable" - UEFI Shell Spec section 2.3\r
+    //\r
+    ImagePath = EfiShellGetFilePathFromDevicePath (DevicePath);\r
+    // The image we're executing isn't necessarily in a filesystem - it might\r
+    // be memory mapped. In this case EfiShellGetFilePathFromDevicePath will\r
+    // return NULL, and we'll leave Argv[0] as UpdateArgcArgv set it.\r
+    if (ImagePath != NULL) {\r
+      if (ShellParamsProtocol.Argv == NULL) {\r
+        // Command line was empty or null.\r
+        // (UpdateArgcArgv sets Argv to NULL when CommandLine is "" or NULL)\r
+        ShellParamsProtocol.Argv = AllocatePool (sizeof (CHAR16 *));\r
+        if (ShellParamsProtocol.Argv == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          goto Cleanup;\r
+        }\r
+        ShellParamsProtocol.Argc = 1;\r
+      } else {\r
+        // Free the string UpdateArgcArgv put in Argv[0];\r
+        FreePool (ShellParamsProtocol.Argv[0]);\r
+      }\r
+      ShellParamsProtocol.Argv[0] = ImagePath;\r
+    }\r
+\r
     Status = gBS->InstallProtocolInterface(&NewHandle, &gEfiShellParametersProtocolGuid, EFI_NATIVE_INTERFACE, &ShellParamsProtocol);\r
     ASSERT_EFI_ERROR(Status);\r
 \r
     ///@todo initialize and install ShellInterface protocol on the new image for compatibility if - PcdGetBool(PcdShellSupportOldProtocols)\r
 \r
     //\r
-    // now start the image and if the caller wanted the return code pass it to them...\r
+    // now start the image, passing up exit data if the caller requested it\r
     //\r
     if (!EFI_ERROR(Status)) {\r
-      if (StatusCode != NULL) {\r
-        *StatusCode = gBS->StartImage(NewHandle, NULL, NULL);\r
-      } else {\r
-        Status      = gBS->StartImage(NewHandle, NULL, NULL);\r
-      }\r
+      Status      = gBS->StartImage(\r
+                          NewHandle,\r
+                          ExitDataSizePtr,\r
+                          ExitData\r
+                          );\r
     }\r
 \r
     //\r
     // Cleanup (and dont overwrite errors)\r
     //\r
     if (EFI_ERROR(Status)) {\r
-      gBS->UninstallProtocolInterface(NewHandle, &gEfiShellParametersProtocolGuid, &ShellParamsProtocol);\r
+      CleanupStatus = gBS->UninstallProtocolInterface(\r
+                            NewHandle,\r
+                            &gEfiShellParametersProtocolGuid,\r
+                            &ShellParamsProtocol\r
+                            );\r
+      ASSERT_EFI_ERROR(CleanupStatus);\r
     } else {\r
-      Status = gBS->UninstallProtocolInterface(NewHandle, &gEfiShellParametersProtocolGuid, &ShellParamsProtocol);\r
-      ASSERT_EFI_ERROR(Status);\r
+      CleanupStatus = gBS->UninstallProtocolInterface(\r
+                            NewHandle,\r
+                            &gEfiShellParametersProtocolGuid,\r
+                            &ShellParamsProtocol\r
+                            );\r
+      ASSERT_EFI_ERROR(CleanupStatus);\r
     }\r
   }\r
 \r
   if (!IsListEmpty(&OrigEnvs)) {\r
     if (EFI_ERROR(Status)) {\r
-      SetEnvironmentVariableList(&OrigEnvs);\r
+      CleanupStatus = SetEnvironmentVariableList(&OrigEnvs);\r
+      ASSERT_EFI_ERROR(CleanupStatus);\r
     } else {\r
-      Status = SetEnvironmentVariableList(&OrigEnvs);\r
+      CleanupStatus = SetEnvironmentVariableList(&OrigEnvs);\r
+      ASSERT_EFI_ERROR (CleanupStatus);\r
     }\r
   }\r
 \r
@@ -1576,6 +1587,8 @@ EfiShellExecute(
   CHAR16                    *Temp;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevPath;\r
   UINTN                     Size;\r
+  UINTN                     ExitDataSize;\r
+  CHAR16                    *ExitData;\r
 \r
   if ((PcdGet8(PcdShellSupportLevel) < 1)) {\r
     return (EFI_UNSUPPORTED);\r
@@ -1584,18 +1597,18 @@ EfiShellExecute(
   DevPath = AppendDevicePath (ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);\r
 \r
   DEBUG_CODE_BEGIN();\r
-  Temp = gDevPathToText->ConvertDevicePathToText(ShellInfoObject.FileDevPath, TRUE, TRUE);\r
+  Temp = ConvertDevicePathToText(ShellInfoObject.FileDevPath, TRUE, TRUE);\r
   FreePool(Temp);\r
-  Temp = gDevPathToText->ConvertDevicePathToText(ShellInfoObject.ImageDevPath, TRUE, TRUE);\r
+  Temp = ConvertDevicePathToText(ShellInfoObject.ImageDevPath, TRUE, TRUE);\r
   FreePool(Temp);\r
-  Temp = gDevPathToText->ConvertDevicePathToText(DevPath, TRUE, TRUE);\r
+  Temp = ConvertDevicePathToText(DevPath, TRUE, TRUE);\r
   FreePool(Temp);\r
   DEBUG_CODE_END();\r
 \r
   Temp = NULL;\r
   Size = 0;\r
   ASSERT((Temp == NULL && Size == 0) || (Temp != NULL));\r
-  StrnCatGrow(&Temp, &Size, L"Shell.efi ", 0);\r
+  StrnCatGrow(&Temp, &Size, L"Shell.efi -_exit ", 0);\r
   StrnCatGrow(&Temp, &Size, CommandLine, 0);\r
 \r
   Status = InternalShellExecuteDevicePath(\r
@@ -1603,7 +1616,33 @@ EfiShellExecute(
     DevPath,\r
     Temp,\r
     (CONST CHAR16**)Environment,\r
-    StatusCode);\r
+    &ExitDataSize,\r
+    &ExitData);\r
+\r
+    if (Status == EFI_ABORTED) {\r
+      // If the command exited with an error, the shell should put the exit\r
+      // status in ExitData, preceded by a null-terminated string.\r
+      ASSERT (ExitDataSize == StrSize (ExitData) + sizeof (SHELL_STATUS));\r
+\r
+      if (StatusCode != NULL) {\r
+        // Skip the null-terminated string\r
+        ExitData += StrLen (ExitData) + 1;\r
+\r
+        // Use CopyMem to avoid alignment faults\r
+        CopyMem (StatusCode, ExitData, sizeof (SHELL_STATUS));\r
+\r
+        // Convert from SHELL_STATUS to EFI_STATUS\r
+        // EFI_STATUSes have top bit set when they are errors.\r
+        // (See UEFI Spec Appendix D)\r
+        if (*StatusCode != SHELL_SUCCESS) {\r
+          *StatusCode = (EFI_STATUS) *StatusCode | MAX_BIT;\r
+        }\r
+      }\r
+      FreePool (ExitData);\r
+      Status = EFI_SUCCESS;\r
+    } else if ((StatusCode != NULL) && !EFI_ERROR(Status)) {\r
+      *StatusCode = EFI_SUCCESS;\r
+    }\r
 \r
   //\r
   // de-allocate and return\r
@@ -1672,6 +1711,8 @@ EfiShellFreeFileList(
     RemoveEntryList(&ShellFileListItem->Link);\r
     InternalFreeShellFileInfoNode(ShellFileListItem);\r
   }\r
+  InternalFreeShellFileInfoNode(*FileList);\r
+  *FileList = NULL;\r
   return(EFI_SUCCESS);\r
 }\r
 \r
@@ -1693,6 +1734,7 @@ EfiShellRemoveDupInFileList(
 {\r
   EFI_SHELL_FILE_INFO *ShellFileListItem;\r
   EFI_SHELL_FILE_INFO *ShellFileListItem2;\r
+  EFI_SHELL_FILE_INFO *TempNode;\r
 \r
   if (FileList == NULL || *FileList == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
@@ -1710,8 +1752,15 @@ EfiShellRemoveDupInFileList(
             (CHAR16*)ShellFileListItem->FullName,\r
             (CHAR16*)ShellFileListItem2->FullName) == 0\r
          ){\r
+        TempNode = (EFI_SHELL_FILE_INFO *)GetPreviousNode(\r
+                                            &(*FileList)->Link,\r
+                                            &ShellFileListItem2->Link\r
+                                            );\r
         RemoveEntryList(&ShellFileListItem2->Link);\r
         InternalFreeShellFileInfoNode(ShellFileListItem2);\r
+        // Set ShellFileListItem2 to PreviousNode so we don't access Freed\r
+        // memory in GetNextNode in the loop expression above.\r
+        ShellFileListItem2 = TempNode;\r
       }\r
     }\r
   }\r
@@ -1767,7 +1816,6 @@ InternalDuplicateShellFileInfo(
 \r
   @param[in] BasePath         the Path to prepend onto filename for FullPath\r
   @param[in] Status           Status member initial value.\r
-  @param[in] FullName         FullName member initial value.\r
   @param[in] FileName         FileName member initial value.\r
   @param[in] Handle           Handle member initial value.\r
   @param[in] Info             Info struct to copy.\r
@@ -1780,7 +1828,6 @@ EFIAPI
 CreateAndPopulateShellFileInfo(\r
   IN CONST CHAR16 *BasePath,\r
   IN CONST EFI_STATUS Status,\r
-  IN CONST CHAR16 *FullName,\r
   IN CONST CHAR16 *FileName,\r
   IN CONST SHELL_FILE_HANDLE Handle,\r
   IN CONST EFI_FILE_INFO *Info\r
@@ -1797,7 +1844,7 @@ CreateAndPopulateShellFileInfo(
   if (ShellFileListItem == NULL) {\r
     return (NULL);\r
   }\r
-  if (Info != NULL) {\r
+  if (Info != NULL && Info->Size != 0) {\r
     ShellFileListItem->Info = AllocateZeroPool((UINTN)Info->Size);\r
     if (ShellFileListItem->Info == NULL) {\r
       FreePool(ShellFileListItem);\r
@@ -1888,6 +1935,10 @@ EfiShellFindFilesInDir(
     TempString        = NULL;\r
     Size              = 0;\r
     TempString        = StrnCatGrow(&TempString, &Size, ShellFileHandleGetPath(FileDirHandle), 0);\r
+    if (TempString == NULL) {\r
+      SHELL_FREE_NON_NULL(BasePath);\r
+      return (EFI_OUT_OF_RESOURCES);\r
+    }\r
     TempSpot          = StrStr(TempString, L";");\r
 \r
     if (TempSpot != NULL) {\r
@@ -1895,6 +1946,11 @@ EfiShellFindFilesInDir(
     }\r
 \r
     TempString        = StrnCatGrow(&TempString, &Size, BasePath, 0);\r
+    if (TempString == NULL) {\r
+      SHELL_FREE_NON_NULL(BasePath);\r
+      return (EFI_OUT_OF_RESOURCES);\r
+    }\r
+    SHELL_FREE_NON_NULL(BasePath);\r
     BasePath          = TempString;\r
   }\r
 \r
@@ -1909,20 +1965,14 @@ EfiShellFindFilesInDir(
       ; !EFI_ERROR(Status) && !NoFile\r
       ; Status = FileHandleFindNextFile(FileDirHandle, FileInfo, &NoFile)\r
      ){\r
-    TempString  = NULL;\r
-    Size        = 0;\r
     //\r
     // allocate a new EFI_SHELL_FILE_INFO and populate it...\r
     //\r
-    ASSERT((TempString == NULL && Size == 0) || (TempString != NULL));\r
-    TempString = StrnCatGrow(&TempString, &Size, BasePath, 0);\r
-    TempString = StrnCatGrow(&TempString, &Size, FileInfo->FileName, 0);\r
     ShellFileListItem = CreateAndPopulateShellFileInfo(\r
       BasePath,\r
-      EFI_SUCCESS, // success since we didnt fail to open it...\r
-      TempString,\r
+      EFI_SUCCESS,  // success since we didnt fail to open it...\r
       FileInfo->FileName,\r
-      NULL, // no handle since not open\r
+      NULL,         // no handle since not open\r
       FileInfo);\r
 \r
     if (ShellFileList == NULL) {\r
@@ -1945,8 +1995,8 @@ EfiShellFindFilesInDir(
 /**\r
   Updates a file name to be preceeded by the mapped drive name\r
 \r
-  @param[in] BasePath     the Mapped drive name to prepend\r
-  @param[in,out] Path     pointer to pointer to the file name to update.\r
+  @param[in] BasePath      the Mapped drive name to prepend\r
+  @param[in, out] Path     pointer to pointer to the file name to update.\r
 \r
   @retval EFI_SUCCESS\r
   @retval EFI_OUT_OF_RESOURCES\r
@@ -2001,12 +2051,12 @@ UpdateFileName(
   Upon a EFI_SUCCESS return fromt he function any the caller is responsible to call\r
   FreeFileList with FileList.\r
 \r
-  @param[in] FilePattern        The FilePattern to check against.\r
-  @param[in] UnicodeCollation   The pointer to EFI_UNICODE_COLLATION_PROTOCOL structure\r
-  @param[in] FileHandle         The FileHandle to start with\r
-  @param[in,out] FileList       pointer to pointer to list of found files.\r
-  @param[in] ParentNode         The node for the parent. Same file as identified by HANDLE.\r
-  @param[in] MapName            The file system name this file is on.\r
+  @param[in] FilePattern         The FilePattern to check against.\r
+  @param[in] UnicodeCollation    The pointer to EFI_UNICODE_COLLATION_PROTOCOL structure\r
+  @param[in] FileHandle          The FileHandle to start with\r
+  @param[in, out] FileList       pointer to pointer to list of found files.\r
+  @param[in] ParentNode          The node for the parent. Same file as identified by HANDLE.\r
+  @param[in] MapName             The file system name this file is on.\r
 \r
   @retval EFI_SUCCESS           all files were found and the FileList contains a list.\r
   @retval EFI_NOT_FOUND         no files were found\r
@@ -2239,8 +2289,9 @@ EfiShellFindFiles(
 \r
   ASSERT(MapName == NULL);\r
   MapName = StrnCatGrow(&MapName, NULL, PatternCopy, Count);\r
-\r
-  if (!EFI_ERROR(Status)) {\r
+  if (MapName == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+  } else {\r
     RootDevicePath = EfiShellGetDevicePathFromFilePath(PatternCopy);\r
     if (RootDevicePath == NULL) {\r
       Status = EFI_INVALID_PARAMETER;\r
@@ -2759,7 +2810,7 @@ EfiShellSetCurDir(
       MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0);\r
       ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));\r
       MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, DirectoryName, 0);\r
-      if (MapListItem->CurrentDirectoryPath[StrLen(MapListItem->CurrentDirectoryPath)-1] != L'\\') {\r
+      if (MapListItem->CurrentDirectoryPath != NULL && MapListItem->CurrentDirectoryPath[StrLen(MapListItem->CurrentDirectoryPath)-1] != L'\\') {\r
         ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));\r
         MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0);\r
       }\r
@@ -2815,15 +2866,33 @@ EfiShellGetHelpText(
   )\r
 {\r
   CONST CHAR16  *ManFileName;\r
+  CHAR16        *FixCommand;\r
+  EFI_STATUS    Status;\r
 \r
   ASSERT(HelpText != NULL);\r
+  FixCommand = NULL;\r
 \r
   ManFileName = ShellCommandGetManFileNameHandler(Command);\r
 \r
   if (ManFileName != NULL) {\r
     return (ProcessManFile(ManFileName, Command, Sections, NULL, HelpText));\r
   } else {\r
-    return (ProcessManFile(Command, Command, Sections, NULL, HelpText));\r
+    if ((StrLen(Command)> 4)\r
+    && (Command[StrLen(Command)-1] == L'i' || Command[StrLen(Command)-1] == L'I')\r
+    && (Command[StrLen(Command)-2] == L'f' || Command[StrLen(Command)-2] == L'F')\r
+    && (Command[StrLen(Command)-3] == L'e' || Command[StrLen(Command)-3] == L'E')\r
+    && (Command[StrLen(Command)-4] == L'.')\r
+    ) {\r
+      FixCommand = AllocateZeroPool(StrSize(Command) - 4 * sizeof (CHAR16));\r
+      ASSERT(FixCommand != NULL);\r
+\r
+      StrnCpy(FixCommand, Command, StrLen(Command)-4);\r
+      Status = ProcessManFile(FixCommand, FixCommand, Sections, NULL, HelpText);\r
+      FreePool(FixCommand);\r
+      return Status;\r
+    } else {\r
+      return (ProcessManFile(Command, Command, Sections, NULL, HelpText));\r
+    }\r
   }\r
 }\r
 \r
@@ -2884,7 +2953,6 @@ InternalEfiShellGetListAlias(
   UINTN             NameSize;\r
   CHAR16            *RetVal;\r
   UINTN             RetSize;\r
-  CHAR16            *Alias;\r
 \r
   Status = gRT->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS, &MaxStorSize, &RemStorSize, &MaxVarSize);\r
   ASSERT_EFI_ERROR(Status);\r
@@ -2910,7 +2978,6 @@ InternalEfiShellGetListAlias(
       break;\r
     }\r
     if (CompareGuid(&Guid, &gShellAliasGuid)){\r
-      Alias = GetVariable(VariableName, &gShellAliasGuid);\r
       ASSERT((RetVal == NULL && RetSize == 0) || (RetVal != NULL));\r
       RetVal = StrnCatGrow(&RetVal, &RetSize, VariableName, 0);\r
       RetVal = StrnCatGrow(&RetVal, &RetSize, L";", 0);\r
@@ -3124,7 +3191,7 @@ EFI_SHELL_PROTOCOL         mShellProtocol = {
 \r
   This must be removed via calling CleanUpShellProtocol().\r
 \r
-  @param[in,out] NewShell   The pointer to the pointer to the structure\r
+  @param[in, out] NewShell   The pointer to the pointer to the structure\r
   to install.\r
 \r
   @retval EFI_SUCCESS     The operation was successful.\r
@@ -3253,7 +3320,7 @@ CreatePopulateInstallShellProtocol (
   Free all memory and restore the system to the state it was in before calling\r
   CreatePopulateInstallShellProtocol.\r
 \r
-  @param[in,out] NewShell   The pointer to the new shell protocol structure.\r
+  @param[in, out] NewShell   The pointer to the new shell protocol structure.\r
 \r
   @retval EFI_SUCCESS       The operation was successful.\r
 **/\r
@@ -3327,9 +3394,9 @@ NotificationFunction(
   IN EFI_KEY_DATA *KeyData\r
   )\r
 {\r
-//  ShellPrintEx(-1,-1,L"  <Notify>  ");\r
-   if ((KeyData->Key.UnicodeChar == L'c' || KeyData->Key.UnicodeChar == 3) &&\r
-      (KeyData->KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED) || KeyData->KeyState.KeyShiftState  == (EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED))\r
+  if ( ((KeyData->Key.UnicodeChar == L'c') &&\r
+        (KeyData->KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED) || KeyData->KeyState.KeyShiftState  == (EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED))) ||\r
+      (KeyData->Key.UnicodeChar == 3)\r
       ){ \r
     if (ShellInfoObject.NewEfiShellProtocol->ExecutionBreak == NULL) {\r
       return (EFI_UNSUPPORTED);\r