]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c
Rollback the change to EFI_BOOT_KEY_DATA structure since UEFI Spec adds the clarifica...
[mirror_edk2.git] / ShellPkg / Library / UefiShellInstall1CommandsLib / Bcfg.c
index 81d738964ea8f691170dd43e32d20c3ea6ad3320..b91b34ffaeb1cc544509044629fdb8f3b1ebd270 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for bcfg shell Install1 function.\r
 \r
-  Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2013, 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
@@ -107,6 +107,7 @@ UpdateOptionalData(
     //\r
     // Allocate new struct and discard old optional data.\r
     //\r
+    ASSERT (OriginalData != NULL);\r
     OriginalOptionDataSize  = sizeof(UINT32) + sizeof(UINT16) + StrSize(((CHAR16*)(OriginalData + sizeof(UINT32) + sizeof(UINT16))));\r
     OriginalOptionDataSize += (*(UINT16*)(OriginalData + sizeof(UINT32)));\r
     OriginalOptionDataSize -= OriginalSize;\r
@@ -139,8 +140,8 @@ UpdateOptionalData(
 /**\r
   This function will get a CRC for a boot option.\r
 \r
-  @param[in, out] Crc     The CRC value to return.\r
-  @param[in]      Index   The boot option index to CRC.\r
+  @param[in, out] Crc         The CRC value to return.\r
+  @param[in]      BootIndex   The boot option index to CRC.\r
 \r
   @retval EFI_SUCCESS           The CRC was sucessfully returned.\r
   @retval other                 A error occured.\r
@@ -282,7 +283,6 @@ BcfgAddInstall1(
   EFI_STATUS                Status;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
   EFI_DEVICE_PATH_PROTOCOL  *FilePath;\r
-  EFI_DEVICE_PATH_PROTOCOL  *FileNode;\r
   CHAR16                    *Str;\r
   UINT8                     *TempByteBuffer;\r
   UINT8                     *TempByteStart;\r
@@ -317,7 +317,6 @@ BcfgAddInstall1(
 \r
   Str             = NULL;\r
   FilePath        = NULL;\r
-  FileNode        = NULL;\r
   FileList        = NULL;\r
   Handles         = NULL;\r
   ShellStatus     = SHELL_SUCCESS;\r
@@ -514,6 +513,7 @@ BcfgAddInstall1(
 \r
       CopyMem (TempByteBuffer, Desc, DescSize);\r
       TempByteBuffer += DescSize;\r
+      ASSERT (FilePath != NULL);\r
       CopyMem (TempByteBuffer, FilePath, FilePathSize);\r
 \r
       UnicodeSPrint (OptionStr, sizeof(OptionStr), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", TargetLocation);\r
@@ -779,6 +779,11 @@ BcfgAddOptInstall1(
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else {\r
       FileName = StrnCatGrow(&FileName, NULL, Walker+1, 0);\r
+      if (FileName == NULL) {\r
+        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellInstall1HiiHandle);\r
+        ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+        return (ShellStatus);\r
+      }\r
       Temp2 = StrStr(FileName, L"\"");\r
       ASSERT(Temp2 != NULL);\r
       Temp2[0] = CHAR_NULL;\r
@@ -841,13 +846,13 @@ BcfgAddOptInstall1(
         // Now we know how many EFI_INPUT_KEY structs we need to attach to the end of the EFI_KEY_OPTION struct.  \r
         // Re-allocate with the added information.\r
         //\r
-        KeyOptionBuffer = AllocateCopyPool(sizeof(EFI_KEY_OPTION) + (sizeof(EFI_KEY_DATA) * NewKeyOption.KeyData.Options.InputKeyCount), &NewKeyOption);\r
+        KeyOptionBuffer = AllocateCopyPool(sizeof(EFI_KEY_OPTION) + (sizeof(EFI_INPUT_KEY) * NewKeyOption.KeyData.Options.InputKeyCount), &NewKeyOption);\r
         if (KeyOptionBuffer == NULL) {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellInstall1HiiHandle);\r
           ShellStatus = SHELL_OUT_OF_RESOURCES;\r
         }\r
       }\r
-      for (LoopCounter = 0 ; ShellStatus == SHELL_SUCCESS && LoopCounter < KeyOptionBuffer->KeyData.Options.InputKeyCount; LoopCounter++) {\r
+      for (LoopCounter = 0 ; ShellStatus == SHELL_SUCCESS && LoopCounter < NewKeyOption.KeyData.Options.InputKeyCount; LoopCounter++) {\r
         //\r
         // ScanCode\r
         //\r
@@ -913,7 +918,7 @@ BcfgAddOptInstall1(
           VariableName,\r
           (EFI_GUID*)&gEfiGlobalVariableGuid,\r
           EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
-          sizeof(EFI_KEY_OPTION) + (sizeof(EFI_KEY_DATA) * NewKeyOption.KeyData.Options.InputKeyCount),\r
+          sizeof(EFI_KEY_OPTION) + (sizeof(EFI_INPUT_KEY) * NewKeyOption.KeyData.Options.InputKeyCount),\r
           KeyOptionBuffer);\r
         if (EFI_ERROR(Status)) {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellInstall1HiiHandle, VariableName, Status);\r
@@ -934,33 +939,37 @@ BcfgAddOptInstall1(
       //\r
       // Open the file and populate the data buffer.\r
       //\r
-      ShellStatus = ShellOpenFileByName(\r
+      Status = ShellOpenFileByName(\r
         FileName,\r
         &FileHandle,\r
         EFI_FILE_MODE_READ,\r
         0);\r
-      if (ShellStatus == SHELL_SUCCESS) {\r
-        ShellStatus = ShellGetFileSize(FileHandle, &Intermediate);\r
+      if (!EFI_ERROR(Status)) {\r
+        Status = ShellGetFileSize(FileHandle, &Intermediate);\r
       }\r
       Data = AllocateZeroPool((UINTN)Intermediate);\r
       if (Data == NULL) {\r
         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellInstall1HiiHandle);\r
         ShellStatus = SHELL_OUT_OF_RESOURCES;\r
       }\r
-      if (ShellStatus == SHELL_SUCCESS) {\r
-        ShellStatus = ShellReadFile(FileHandle, &((UINTN)Intermediate), Data);\r
+      if (!EFI_ERROR(Status)) {\r
+        Status = ShellReadFile(FileHandle, (UINTN *)&Intermediate, Data);\r
       }\r
     } else {\r
       Intermediate = StrSize(Data);\r
     }\r
 \r
-    if (ShellStatus == SHELL_SUCCESS && Data != NULL) {\r
+    if (!EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS && Data != NULL) {\r
       Status = UpdateOptionalData(CurrentOrder[OptionIndex], (UINTN)Intermediate, (UINT8*)Data, Target);\r
       if (EFI_ERROR(Status)) {\r
         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellInstall1HiiHandle, VariableName, Status);\r
         ShellStatus = SHELL_INVALID_PARAMETER;\r
       }   \r
     }\r
+    if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellInstall1HiiHandle, VariableName, Status);\r
+      ShellStatus = SHELL_INVALID_PARAMETER;\r
+    }   \r
   }\r
 \r
   SHELL_FREE_NON_NULL(Data);\r
@@ -1032,7 +1041,7 @@ BcfgDisplayDumpInstall1(
     if ((*(UINT16*)(Buffer+4)) != 0) {\r
       DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4));\r
       CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));\r
-      DevPathString = gDevPathToText->ConvertDevicePathToText(DevPath, TRUE, FALSE);\r
+      DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);\r
     } else {\r
       DevPath       = NULL;\r
       DevPathString = NULL;\r