]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
ShellPkg/UefiHandleParsingLib.c: Handle memory allocation failure
[mirror_edk2.git] / ShellPkg / Library / UefiShellBcfgCommandLib / UefiShellBcfgCommandLib.c
index b08aac1bd822eb9c7c439f27df842911fb3a2e28..bf35a35b985d00e32af4e4aa5d1cb285c7e9a014 100644 (file)
@@ -310,6 +310,7 @@ BcfgAdd(
 {\r
   EFI_STATUS                Status;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevPath;\r
   EFI_DEVICE_PATH_PROTOCOL  *FilePath;\r
   CHAR16                    *Str;\r
   UINT8                     *TempByteBuffer;\r
@@ -462,9 +463,9 @@ BcfgAdd(
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_DP), gShellBcfgHiiHandle, L"bcfg", Arg->FullName);  \r
           ShellStatus = SHELL_UNSUPPORTED;\r
         } else {\r
-/*\r
           if (UsePath) {\r
-            DevPath = DevicePath;\r
+            DevPath     = DevicePath;\r
+            ShellStatus = SHELL_INVALID_PARAMETER;\r
             while (!IsDevicePathEnd(DevPath)) {\r
               if ((DevicePathType(DevPath) == MEDIA_DEVICE_PATH) &&\r
                 (DevicePathSubType(DevPath) == MEDIA_HARDDRIVE_DP)) {\r
@@ -472,24 +473,15 @@ BcfgAdd(
                 //\r
                 // If we find it use it instead\r
                 //\r
-                DevicePath = DevPath;\r
+                ShellStatus = SHELL_SUCCESS;\r
+                FilePath    = DuplicateDevicePath (DevPath);\r
                 break;\r
               }\r
               DevPath = NextDevicePathNode(DevPath);\r
             }\r
-            //\r
-            // append the file\r
-            //\r
-            for(StringWalker=Arg->FullName; *StringWalker != CHAR_NULL && *StringWalker != ':'; StringWalker++);\r
-            FileNode = FileDevicePath(NULL, StringWalker+1);\r
-            FilePath = AppendDevicePath(DevicePath, FileNode);\r
-            FreePool(FileNode);\r
           } else {\r
-*/\r
             FilePath = DuplicateDevicePath(DevicePath);\r
-/*\r
           }\r
-*/\r
           FreePool(DevicePath);\r
         }\r
       }\r
@@ -1048,11 +1040,13 @@ BcfgDisplayDump(
   UINTN           BufferSize;\r
   CHAR16          VariableName[12];\r
   UINTN           LoopVar;\r
-  UINTN           LoopVar2;\r
   CHAR16          *DevPathString;\r
-  VOID            *DevPath;\r
+  VOID            *FilePathList;\r
   UINTN           Errors;\r
   EFI_LOAD_OPTION *LoadOption;\r
+  CHAR16          *Description;\r
+  UINTN           DescriptionSize;\r
+  UINTN           OptionalDataOffset;\r
 \r
   if (OrderCount == 0) {\r
     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_BCFG_NONE), gShellBcfgHiiHandle, L"bcfg");  \r
@@ -1064,7 +1058,6 @@ BcfgDisplayDump(
   for (LoopVar = 0 ; LoopVar < OrderCount ; LoopVar++) {\r
     Buffer        = NULL;\r
     BufferSize    = 0;\r
-    DevPath       = NULL;\r
     DevPathString = NULL;\r
 \r
     UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Op, CurrentOrder[LoopVar]);\r
@@ -1108,15 +1101,19 @@ BcfgDisplayDump(
       ++Errors;\r
       goto Cleanup;\r
     }\r
-    LoadOption = (EFI_LOAD_OPTION *)Buffer;\r
+\r
+    LoadOption      = (EFI_LOAD_OPTION *)Buffer;\r
+    Description     = (CHAR16*)(Buffer + sizeof (EFI_LOAD_OPTION));\r
+    DescriptionSize = StrSize (Description);\r
 \r
     if (LoadOption->FilePathListLength != 0) {\r
-      DevPath = AllocateZeroPool(LoadOption->FilePathListLength);\r
-      if (DevPath != NULL) {\r
-        CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), LoadOption->FilePathListLength);\r
-        DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);\r
-      }\r
+      FilePathList = (UINT8 *)Description + DescriptionSize;\r
+      DevPathString = ConvertDevicePathToText(FilePathList, TRUE, FALSE);\r
     }\r
+\r
+    OptionalDataOffset = sizeof *LoadOption + DescriptionSize +\r
+                         LoadOption->FilePathListLength;\r
+\r
     ShellPrintHiiEx(\r
       -1,\r
       -1,\r
@@ -1125,32 +1122,23 @@ BcfgDisplayDump(
       gShellBcfgHiiHandle,\r
       LoopVar,\r
       VariableName,\r
-      (CHAR16*)(Buffer+6),\r
+      Description,\r
       DevPathString,\r
-      (StrSize((CHAR16*)(Buffer+6)) + LoadOption->FilePathListLength + 6) <= BufferSize?L'N':L'Y');\r
-    if (VerboseOutput) {\r
-      for (LoopVar2 = (StrSize((CHAR16*)(Buffer+6)) + LoadOption->FilePathListLength + 6);LoopVar2<BufferSize;LoopVar2++){\r
-        ShellPrintEx(\r
-          -1,\r
-          -1,\r
-          NULL,\r
-          L"%02x",\r
-          Buffer[LoopVar2]);\r
-      }\r
-      ShellPrintEx(\r
-        -1,\r
-        -1,\r
-        NULL,\r
-        L"\r\n");\r
+      OptionalDataOffset >= BufferSize ? L'N' : L'Y'\r
+      );\r
+    if (VerboseOutput && (OptionalDataOffset < BufferSize)) {\r
+      DumpHex (\r
+        2,                               // Indent\r
+        0,                               // Offset (displayed)\r
+        BufferSize - OptionalDataOffset, // DataSize\r
+        Buffer + OptionalDataOffset      // UserData\r
+        );\r
     }\r
 \r
 Cleanup:\r
     if (Buffer != NULL) {\r
       FreePool(Buffer);\r
     }\r
-    if (DevPath != NULL) {\r
-      FreePool(DevPath);\r
-    }\r
     if (DevPathString != NULL) {\r
       FreePool(DevPathString);\r
     }\r