X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellBcfgCommandLib%2FUefiShellBcfgCommandLib.c;h=bf35a35b985d00e32af4e4aa5d1cb285c7e9a014;hb=f86a5c346578a9503f7383c6eb77ce256f33b605;hp=7e118eb771e6ff4a8f79ce982fa55be738240646;hpb=356c55357980f2ffc7638d0429a1bb5a9e84d181;p=mirror_edk2.git diff --git a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c index 7e118eb771..bf35a35b98 100644 --- a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c +++ b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c @@ -1,8 +1,8 @@ /** @file Main file for BCFG command. - Copyright (c) 2014 - 2015, Hewlett-Packard Development Company, L.P.
- Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.
+ (C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.
+ Copyright (c) 2010 - 2015, 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 @@ -310,6 +310,7 @@ BcfgAdd( { EFI_STATUS Status; EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_DEVICE_PATH_PROTOCOL *DevPath; EFI_DEVICE_PATH_PROTOCOL *FilePath; CHAR16 *Str; UINT8 *TempByteBuffer; @@ -353,7 +354,7 @@ BcfgAdd( if (UseHandle) { CurHandle = ConvertHandleIndexToHandle(HandleNumber); if (CurHandle == NULL) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellBcfgHiiHandle, L"Handle Number"); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", L"Handle Number"); ShellStatus = SHELL_INVALID_PARAMETER; } else { if (Target == BcfgTargetBootOrder) { @@ -462,9 +463,9 @@ BcfgAdd( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_DP), gShellBcfgHiiHandle, L"bcfg", Arg->FullName); ShellStatus = SHELL_UNSUPPORTED; } else { -/* if (UsePath) { - DevPath = DevicePath; + DevPath = DevicePath; + ShellStatus = SHELL_INVALID_PARAMETER; while (!IsDevicePathEnd(DevPath)) { if ((DevicePathType(DevPath) == MEDIA_DEVICE_PATH) && (DevicePathSubType(DevPath) == MEDIA_HARDDRIVE_DP)) { @@ -472,24 +473,15 @@ BcfgAdd( // // If we find it use it instead // - DevicePath = DevPath; + ShellStatus = SHELL_SUCCESS; + FilePath = DuplicateDevicePath (DevPath); break; } DevPath = NextDevicePathNode(DevPath); } - // - // append the file - // - for(StringWalker=Arg->FullName; *StringWalker != CHAR_NULL && *StringWalker != ':'; StringWalker++); - FileNode = FileDevicePath(NULL, StringWalker+1); - FilePath = AppendDevicePath(DevicePath, FileNode); - FreePool(FileNode); } else { -*/ FilePath = DuplicateDevicePath(DevicePath); -/* } -*/ FreePool(DevicePath); } } @@ -1043,23 +1035,31 @@ BcfgDisplayDump( IN CONST BOOLEAN VerboseOutput ) { - EFI_STATUS Status; - UINT8 *Buffer; - UINTN BufferSize; - CHAR16 VariableName[12]; - UINTN LoopVar; - UINTN LoopVar2; - CHAR16 *DevPathString; - VOID *DevPath; + EFI_STATUS Status; + UINT8 *Buffer; + UINTN BufferSize; + CHAR16 VariableName[12]; + UINTN LoopVar; + CHAR16 *DevPathString; + VOID *FilePathList; + UINTN Errors; + EFI_LOAD_OPTION *LoadOption; + CHAR16 *Description; + UINTN DescriptionSize; + UINTN OptionalDataOffset; if (OrderCount == 0) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_BCFG_NONE), gShellBcfgHiiHandle, L"bcfg"); return (SHELL_SUCCESS); } + Errors = 0; + for (LoopVar = 0 ; LoopVar < OrderCount ; LoopVar++) { - Buffer = NULL; - BufferSize = 0; + Buffer = NULL; + BufferSize = 0; + DevPathString = NULL; + UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Op, CurrentOrder[LoopVar]); Status = gRT->GetVariable( @@ -1080,21 +1080,40 @@ BcfgDisplayDump( if (EFI_ERROR(Status) || Buffer == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_READ_FAIL), gShellBcfgHiiHandle, L"bcfg", VariableName); - return (SHELL_INVALID_PARAMETER); + ++Errors; + goto Cleanup; } - if ((*(UINT16*)(Buffer+4)) != 0) { - DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4)); - if (DevPath == NULL) { - DevPathString = NULL; - } else { - CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4)); - DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE); - } - } else { - DevPath = NULL; - DevPathString = NULL; + // + // We expect the Attributes, FilePathListLength, and L'\0'-terminated + // Description fields to be present. + // + if (BufferSize < sizeof *LoadOption + sizeof (CHAR16)) { + ShellPrintHiiEx ( + -1, + -1, + NULL, + STRING_TOKEN (STR_BCFG_VAR_CORRUPT), + gShellBcfgHiiHandle, + L"bcfg", + VariableName + ); + ++Errors; + goto Cleanup; + } + + LoadOption = (EFI_LOAD_OPTION *)Buffer; + Description = (CHAR16*)(Buffer + sizeof (EFI_LOAD_OPTION)); + DescriptionSize = StrSize (Description); + + if (LoadOption->FilePathListLength != 0) { + FilePathList = (UINT8 *)Description + DescriptionSize; + DevPathString = ConvertDevicePathToText(FilePathList, TRUE, FALSE); } + + OptionalDataOffset = sizeof *LoadOption + DescriptionSize + + LoadOption->FilePathListLength; + ShellPrintHiiEx( -1, -1, @@ -1103,36 +1122,28 @@ BcfgDisplayDump( gShellBcfgHiiHandle, LoopVar, VariableName, - (CHAR16*)(Buffer+6), + Description, DevPathString, - (StrSize((CHAR16*)(Buffer+6)) + *(UINT16*)(Buffer+4) + 6) <= BufferSize?L'N':L'Y'); - if (VerboseOutput) { - for (LoopVar2 = (StrSize((CHAR16*)(Buffer+6)) + *(UINT16*)(Buffer+4) + 6);LoopVar2= BufferSize ? L'N' : L'Y' + ); + if (VerboseOutput && (OptionalDataOffset < BufferSize)) { + DumpHex ( + 2, // Indent + 0, // Offset (displayed) + BufferSize - OptionalDataOffset, // DataSize + Buffer + OptionalDataOffset // UserData + ); } +Cleanup: if (Buffer != NULL) { FreePool(Buffer); } - if (DevPath != NULL) { - FreePool(DevPath); - } if (DevPathString != NULL) { FreePool(DevPathString); } } - return (SHELL_SUCCESS); + return (Errors > 0) ? SHELL_INVALID_PARAMETER : SHELL_SUCCESS; } /** @@ -1379,7 +1390,7 @@ ShellCommandRunBcfg ( Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE); CurrentOperation.Number1 = (UINT16)Intermediate; if (CurrentOperation.Number1 >= Count){ - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), L"bcfg", gShellBcfgHiiHandle, Count); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count); ShellStatus = SHELL_INVALID_PARAMETER; } else { CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);