]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ShellProtocol.c
Roll back check in r15180 which caused the shell always returns EFI_ABORTED no matter...
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellProtocol.c
index fb94a5b45e7e0b75920f08b28e2c92d1b0343c2e..b0303962ff6939cb3771452973b6c537360aba74 100644 (file)
@@ -530,18 +530,17 @@ EfiShellGetDevicePathFromFilePath(
     if (Cwd == NULL) {\r
       return (NULL);\r
     }\r
-    Size = StrSize(Cwd);\r
-    Size += StrSize(Path);\r
+    Size = StrSize(Cwd) + StrSize(Path) - sizeof(CHAR16);\r
     NewPath = AllocateZeroPool(Size);\r
     if (NewPath == NULL) {\r
       return (NULL);\r
     }\r
-    StrCpy(NewPath, Cwd);\r
+    StrnCpy(NewPath, Cwd, Size/sizeof(CHAR16)-1);\r
     if (*Path == L'\\') {\r
       Path++;\r
       while (PathRemoveLastItem(NewPath)) ;\r
     }\r
-    StrCat(NewPath, Path);\r
+    StrnCat(NewPath, Path, Size/sizeof(CHAR16) - 1 - StrLen(NewPath));\r
     DevicePathForReturn = EfiShellGetDevicePathFromFilePath(NewPath);\r
     FreePool(NewPath);\r
     return (DevicePathForReturn);\r
@@ -1402,8 +1401,6 @@ EfiShellEnablePageBreak (
                                 is NULL, then the current shell environment is used.\r
                             \r
   @param[out] StartImageStatus  Returned status from gBS->StartImage.\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
@@ -1418,9 +1415,7 @@ InternalShellExecuteDevicePath(
   IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
   IN CONST CHAR16                   *CommandLine OPTIONAL,\r
   IN CONST CHAR16                   **Environment OPTIONAL,\r
-  OUT EFI_STATUS                    *StartImageStatus OPTIONAL,\r
-  OUT UINTN                         *ExitDataSize OPTIONAL,\r
-  OUT CHAR16                        **ExitData OPTIONAL\r
+  OUT EFI_STATUS                    *StartImageStatus OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                    Status;\r
@@ -1430,18 +1425,10 @@ InternalShellExecuteDevicePath(
   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
   UINTN                         Index;\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
+  CHAR16                        *Walker;\r
+  CHAR16                        *NewCmdLine;\r
 \r
   if (ParentImageHandle == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
@@ -1450,6 +1437,17 @@ InternalShellExecuteDevicePath(
   InitializeListHead(&OrigEnvs);\r
 \r
   NewHandle = NULL;\r
+  \r
+  NewCmdLine = AllocateCopyPool (StrSize (CommandLine), CommandLine);\r
+  if (NewCmdLine == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  for (Walker = NewCmdLine; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {\r
+    if (*Walker == L'^' && *(Walker+1) == L'#') {\r
+      CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));\r
+    }\r
+  }\r
 \r
   //\r
   // Load the image with:\r
@@ -1479,9 +1477,9 @@ InternalShellExecuteDevicePath(
 \r
   if (!EFI_ERROR(Status)) {\r
     ASSERT(LoadedImage->LoadOptionsSize == 0);\r
-    if (CommandLine != NULL) {\r
-      LoadedImage->LoadOptionsSize  = (UINT32)StrSize(CommandLine);\r
-      LoadedImage->LoadOptions      = (VOID*)CommandLine;\r
+    if (NewCmdLine != NULL) {\r
+      LoadedImage->LoadOptionsSize  = (UINT32)StrSize(NewCmdLine);\r
+      LoadedImage->LoadOptions      = (VOID*)NewCmdLine;\r
     }\r
 \r
     //\r
@@ -1500,7 +1498,7 @@ InternalShellExecuteDevicePath(
     ShellParamsProtocol.StdIn   = ShellInfoObject.NewShellParametersProtocol->StdIn;\r
     ShellParamsProtocol.StdOut  = ShellInfoObject.NewShellParametersProtocol->StdOut;\r
     ShellParamsProtocol.StdErr  = ShellInfoObject.NewShellParametersProtocol->StdErr;\r
-    Status = UpdateArgcArgv(&ShellParamsProtocol, CommandLine, NULL, NULL);\r
+    Status = UpdateArgcArgv(&ShellParamsProtocol, NewCmdLine, NULL, NULL);\r
     ASSERT_EFI_ERROR(Status);\r
     //\r
     // Replace Argv[0] with the full path of the binary we're executing:\r
@@ -1535,13 +1533,13 @@ InternalShellExecuteDevicePath(
     ///@todo initialize and install ShellInterface protocol on the new image for compatibility if - PcdGetBool(PcdShellSupportOldProtocols)\r
 \r
     //\r
-    // now start the image, passing up exit data if the caller requested it\r
+    // now start the image and if the caller wanted the return code pass it to them...\r
     //\r
     if (!EFI_ERROR(Status)) {\r
       StartStatus      = gBS->StartImage(\r
                           NewHandle,\r
-                          ExitDataSizePtr,\r
-                          ExitData\r
+                          0,\r
+                          NULL\r
                           );\r
       if (StartImageStatus != NULL) {\r
         *StartImageStatus = StartStatus;\r
@@ -1579,6 +1577,8 @@ FreeAlloc:
     ASSERT_EFI_ERROR (CleanupStatus);\r
   }\r
 \r
+  FreePool (NewCmdLine);\r
+\r
   return(Status);\r
 }\r
 /**\r
@@ -1628,8 +1628,6 @@ 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
@@ -1657,32 +1655,7 @@ 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
-    }\r
+    StatusCode);\r
 \r
   //\r
   // de-allocate and return\r
@@ -1846,10 +1819,9 @@ InternalDuplicateShellFileInfo(
   if (NewNode == NULL) {\r
     return (NULL);\r
   }\r
-  NewNode->FullName = AllocateZeroPool(StrSize(Node->FullName));\r
-\r
-  NewNode->FileName = AllocateZeroPool(StrSize(Node->FileName));\r
-  NewNode->Info     = AllocateZeroPool((UINTN)Node->Info->Size);\r
+  NewNode->FullName = AllocateCopyPool(StrSize(Node->FullName), Node->FullName);\r
+  NewNode->FileName = AllocateCopyPool(StrSize(Node->FileName), Node->FileName);\r
+  NewNode->Info     = AllocateCopyPool((UINTN)Node->Info->Size, Node->Info);\r
   if ( NewNode->FullName == NULL\r
     || NewNode->FileName == NULL\r
     || NewNode->Info == NULL\r
@@ -1865,9 +1837,6 @@ InternalDuplicateShellFileInfo(
   if (!Save) {\r
     Node->Handle = NULL;\r
   }\r
-  StrCpy((CHAR16*)NewNode->FullName, Node->FullName);\r
-  StrCpy((CHAR16*)NewNode->FileName, Node->FileName);\r
-  CopyMem(NewNode->Info, Node->Info, (UINTN)Node->Info->Size);\r
 \r
   return((EFI_SHELL_FILE_INFO*)NewNode);\r
 }\r
@@ -2313,8 +2282,8 @@ ShellSearchHandle(
             if (NewFullName == NULL) {\r
               Status = EFI_OUT_OF_RESOURCES;\r
             } else {\r
-              StrCpy(NewFullName, MapName);\r
-              StrCat(NewFullName, ShellInfoNode->FullName+1);\r
+              StrnCpy(NewFullName, MapName, Size/sizeof(CHAR16)-1);\r
+              StrnCat(NewFullName, ShellInfoNode->FullName+1, (Size/sizeof(CHAR16))-StrLen(NewFullName)-1);\r
               FreePool((VOID*)ShellInfoNode->FullName);\r
               ShellInfoNode->FullName = NewFullName;\r
             }\r
@@ -2437,11 +2406,10 @@ EfiShellFindFiles(
   RootDevicePath = NULL;\r
   RootFileHandle = NULL;\r
   MapName        = NULL;\r
-  PatternCopy = AllocateZeroPool(StrSize(FilePattern));\r
+  PatternCopy = AllocateCopyPool(StrSize(FilePattern), FilePattern);\r
   if (PatternCopy == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
-  StrCpy(PatternCopy, FilePattern);\r
 \r
   PatternCopy = PathCleanUpDirectories(PatternCopy);\r
 \r
@@ -2645,7 +2613,7 @@ EfiShellGetEnvEx(
       ; Node = (ENV_VAR_LIST*)GetNextNode(&List, &Node->Link)\r
      ){\r
       ASSERT(Node->Key != NULL);\r
-      StrCpy(CurrentWriteLocation, Node->Key);\r
+      StrnCpy(CurrentWriteLocation, Node->Key,  (Size)/sizeof(CHAR16) - (CurrentWriteLocation - ((CHAR16*)Buffer)) - 1);\r
       CurrentWriteLocation += StrLen(CurrentWriteLocation) + 1;\r
     }\r
 \r
@@ -2669,7 +2637,6 @@ EfiShellGetEnvEx(
       // Allocate the space and recall the get function\r
       //\r
       Buffer = AllocateZeroPool(Size);\r
-      ASSERT(Buffer != NULL);\r
       Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(Name, Attributes, &Size, Buffer);\r
     }\r
     //\r
@@ -3187,7 +3154,7 @@ InternalEfiShellGetListAlias(
   \r
   @return        The null-terminated string converted into all lowercase.  \r
 **/\r
-STATIC CHAR16 *\r
+CHAR16 *\r
 ToLower (\r
   CHAR16 *Str\r
   )\r