X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellDebug1CommandsLib%2FBcfg.c;h=c26fad7b38b2b52ed55e9f400b45c59fc59824df;hb=e755a4ca10aad316c3620223206d63982793b26c;hp=10ce33eee9f348df4573f0a22f649fdab9649915;hpb=cff7bffbb55bf9bf0162370b78ae202bf45fdd57;p=mirror_edk2.git diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c index 10ce33eee9..c26fad7b38 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c @@ -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; @@ -779,6 +790,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 +842,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 +857,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 +929,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); @@ -929,38 +945,42 @@ BcfgAddOptDebug1( // ASSERT(FileName == NULL || Data == NULL); - if (ShellStatus == SHELL_SUCCESS && FileName != NULL || Data != NULL) { + if (ShellStatus == SHELL_SUCCESS && (FileName != NULL || Data != NULL)) { if (FileName != NULL) { // // 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);