X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellDebug1CommandsLib%2FBcfg.c;h=73831d267e1cbf249ef9760e94351ee90c01d6b7;hp=fed38564e93c3941cd7ed9f974cf9727ba2266d3;hb=e3df6949e7e2a4578660d4079988487a147c91b7;hpb=479f85bb721765fefc43bb98bff999e2b3bc779a diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c index fed38564e9..73831d267e 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c @@ -1,7 +1,7 @@ /** @file Main file for bcfg shell Debug1 function. - Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.
+ Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -47,6 +47,16 @@ typedef struct { CONST CHAR16 *OptData; } BGFG_OPERATION; +/** + Get the actual number of entries in EFI_KEY_OPTION.Keys, from 0-3. + + @param KeyOption Pointer to the EFI_KEY_OPTION structure. + + @return Actual number of entries in EFI_KEY_OPTION.Keys. +**/ +#define KEY_OPTION_INPUT_KEY_COUNT(KeyOption) \ + (((KeyOption)->KeyData & EFI_KEY_OPTION_INPUT_KEY_COUNT_MASK) >> LowBitSet32 (EFI_KEY_OPTION_INPUT_KEY_COUNT_MASK)) + /** Update the optional data for a boot or driver option. @@ -107,6 +117,7 @@ UpdateOptionalDataDebug1( // // Allocate new struct and discard old optional data. // + ASSERT (OriginalData != NULL); OriginalOptionDataSize = sizeof(UINT32) + sizeof(UINT16) + StrSize(((CHAR16*)(OriginalData + sizeof(UINT32) + sizeof(UINT16)))); OriginalOptionDataSize += (*(UINT16*)(OriginalData + sizeof(UINT32))); OriginalOptionDataSize -= OriginalSize; @@ -139,8 +150,8 @@ UpdateOptionalDataDebug1( /** This function will get a CRC for a boot option. - @param[in, out] Crc The CRC value to return. - @param[in] Index The boot option index to CRC. + @param[in, out] Crc The CRC value to return. + @param[in] BootIndex The boot option index to CRC. @retval EFI_SUCCESS The CRC was sucessfully returned. @retval other A error occured. @@ -282,7 +293,7 @@ BcfgAddDebug1( EFI_STATUS Status; EFI_DEVICE_PATH_PROTOCOL *DevicePath; EFI_DEVICE_PATH_PROTOCOL *FilePath; - EFI_DEVICE_PATH_PROTOCOL *FileNode; + /* EFI_DEVICE_PATH_PROTOCOL *FileNode; */ CHAR16 *Str; UINT8 *TempByteBuffer; UINT8 *TempByteStart; @@ -317,7 +328,7 @@ BcfgAddDebug1( Str = NULL; FilePath = NULL; - FileNode = NULL; + /* FileNode = NULL; */ FileList = NULL; Handles = NULL; ShellStatus = SHELL_SUCCESS; @@ -514,6 +525,7 @@ BcfgAddDebug1( CopyMem (TempByteBuffer, Desc, DescSize); TempByteBuffer += DescSize; + ASSERT (FilePath != NULL); CopyMem (TempByteBuffer, FilePath, FilePathSize); UnicodeSPrint (OptionStr, sizeof(OptionStr), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", TargetLocation); @@ -779,6 +791,11 @@ BcfgAddOptDebug1( ShellStatus = SHELL_INVALID_PARAMETER; } else { FileName = StrnCatGrow(&FileName, NULL, Walker+1, 0); + if (FileName == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle); + ShellStatus = SHELL_OUT_OF_RESOURCES; + return (ShellStatus); + } Temp2 = StrStr(FileName, L"\""); ASSERT(Temp2 != NULL); Temp2[0] = CHAR_NULL; @@ -826,7 +843,7 @@ BcfgAddOptDebug1( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Walker); ShellStatus = SHELL_INVALID_PARAMETER; } - NewKeyOption.KeyData.PackedValue = (UINT32)Intermediate; + NewKeyOption.KeyData = (UINT32)Intermediate; Temp = StrStr(Walker, L" "); if (Temp != NULL) { Walker = Temp; @@ -841,13 +858,13 @@ BcfgAddOptDebug1( // Now we know how many EFI_INPUT_KEY structs we need to attach to the end of the EFI_KEY_OPTION struct. // Re-allocate with the added information. // - KeyOptionBuffer = AllocateCopyPool(sizeof(EFI_KEY_OPTION) + (sizeof(EFI_KEY_DATA) * NewKeyOption.KeyData.Options.InputKeyCount), &NewKeyOption); + KeyOptionBuffer = AllocateCopyPool(sizeof(EFI_KEY_OPTION) + (sizeof(EFI_KEY_DATA) * KEY_OPTION_INPUT_KEY_COUNT (&NewKeyOption)), &NewKeyOption); if (KeyOptionBuffer == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellDebug1HiiHandle); ShellStatus = SHELL_OUT_OF_RESOURCES; } } - for (LoopCounter = 0 ; ShellStatus == SHELL_SUCCESS && LoopCounter < KeyOptionBuffer->KeyData.Options.InputKeyCount; LoopCounter++) { + for (LoopCounter = 0 ; ShellStatus == SHELL_SUCCESS && LoopCounter < KEY_OPTION_INPUT_KEY_COUNT (&NewKeyOption); LoopCounter++) { // // ScanCode // @@ -913,7 +930,7 @@ BcfgAddOptDebug1( VariableName, (EFI_GUID*)&gEfiGlobalVariableGuid, EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS, - sizeof(EFI_KEY_OPTION) + (sizeof(EFI_KEY_DATA) * NewKeyOption.KeyData.Options.InputKeyCount), + sizeof(EFI_KEY_OPTION) + (sizeof(EFI_KEY_DATA) * KEY_OPTION_INPUT_KEY_COUNT (&NewKeyOption)), KeyOptionBuffer); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellDebug1HiiHandle, VariableName, Status); @@ -934,33 +951,37 @@ BcfgAddOptDebug1( // // Open the file and populate the data buffer. // - ShellStatus = ShellOpenFileByName( + Status = ShellOpenFileByName( FileName, &FileHandle, EFI_FILE_MODE_READ, 0); - if (ShellStatus == SHELL_SUCCESS) { - ShellStatus = ShellGetFileSize(FileHandle, &Intermediate); + if (!EFI_ERROR(Status)) { + Status = ShellGetFileSize(FileHandle, &Intermediate); } Data = AllocateZeroPool((UINTN)Intermediate); if (Data == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellDebug1HiiHandle); ShellStatus = SHELL_OUT_OF_RESOURCES; } - if (ShellStatus == SHELL_SUCCESS) { - ShellStatus = ShellReadFile(FileHandle, &((UINTN)Intermediate), Data); + if (!EFI_ERROR(Status)) { + Status = ShellReadFile(FileHandle, (UINTN *)&Intermediate, Data); } } else { Intermediate = StrSize(Data); } - if (ShellStatus == SHELL_SUCCESS && Data != NULL) { + if (!EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS && Data != NULL) { Status = UpdateOptionalDataDebug1(CurrentOrder[OptionIndex], (UINTN)Intermediate, (UINT8*)Data, Target); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellDebug1HiiHandle, VariableName, Status); ShellStatus = SHELL_INVALID_PARAMETER; } } + if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellDebug1HiiHandle, VariableName, Status); + ShellStatus = SHELL_INVALID_PARAMETER; + } } SHELL_FREE_NON_NULL(Data); @@ -1032,7 +1053,7 @@ BcfgDisplayDumpDebug1( if ((*(UINT16*)(Buffer+4)) != 0) { DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4)); CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4)); - DevPathString = gDevPathToText->ConvertDevicePathToText(DevPath, TRUE, FALSE); + DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE); } else { DevPath = NULL; DevPathString = NULL;