Main file for BCFG command.\r
\r
(C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR>\r
- Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2010 - 2015, 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
if (UseHandle) {\r
CurHandle = ConvertHandleIndexToHandle(HandleNumber);\r
if (CurHandle == NULL) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellBcfgHiiHandle, L"Handle Number");\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", L"Handle Number");\r
ShellStatus = SHELL_INVALID_PARAMETER;\r
} else {\r
if (Target == BcfgTargetBootOrder) {\r
IN CONST BOOLEAN VerboseOutput\r
)\r
{\r
- EFI_STATUS Status;\r
- UINT8 *Buffer;\r
- UINTN BufferSize;\r
- CHAR16 VariableName[12];\r
- UINTN LoopVar;\r
- UINTN LoopVar2;\r
- CHAR16 *DevPathString;\r
- VOID *DevPath;\r
+ EFI_STATUS Status;\r
+ UINT8 *Buffer;\r
+ UINTN BufferSize;\r
+ CHAR16 VariableName[12];\r
+ UINTN LoopVar;\r
+ UINTN LoopVar2;\r
+ CHAR16 *DevPathString;\r
+ VOID *DevPath;\r
+ UINTN Errors;\r
+ EFI_LOAD_OPTION *LoadOption;\r
+ CHAR16 *Description;\r
+ UINTN DescriptionSize;\r
\r
if (OrderCount == 0) {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_BCFG_NONE), gShellBcfgHiiHandle, L"bcfg"); \r
return (SHELL_SUCCESS);\r
}\r
\r
+ Errors = 0;\r
+\r
for (LoopVar = 0 ; LoopVar < OrderCount ; LoopVar++) {\r
- Buffer = NULL;\r
- BufferSize = 0;\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
\r
Status = gRT->GetVariable(\r
\r
if (EFI_ERROR(Status) || Buffer == NULL) {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_READ_FAIL), gShellBcfgHiiHandle, L"bcfg", VariableName); \r
- return (SHELL_INVALID_PARAMETER);\r
+ ++Errors;\r
+ goto Cleanup;\r
}\r
\r
- if ((*(UINT16*)(Buffer+4)) != 0) {\r
- DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4));\r
- if (DevPath == NULL) {\r
- DevPathString = NULL;\r
- } else {\r
- CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));\r
+ //\r
+ // We expect the Attributes, FilePathListLength, and L'\0'-terminated\r
+ // Description fields to be present.\r
+ //\r
+ if (BufferSize < sizeof *LoadOption + sizeof (CHAR16)) {\r
+ ShellPrintHiiEx (\r
+ -1,\r
+ -1,\r
+ NULL,\r
+ STRING_TOKEN (STR_BCFG_VAR_CORRUPT),\r
+ gShellBcfgHiiHandle,\r
+ L"bcfg",\r
+ VariableName\r
+ );\r
+ ++Errors;\r
+ goto Cleanup;\r
+ }\r
+\r
+ LoadOption = (EFI_LOAD_OPTION *)Buffer;\r
+ Description = (CHAR16 *)(&LoadOption->FilePathListLength + 1);\r
+ DescriptionSize = StrSize (Description);\r
+\r
+ if (LoadOption->FilePathListLength != 0) {\r
+ DevPath = AllocateZeroPool(LoadOption->FilePathListLength);\r
+ if (DevPath != NULL) {\r
+ CopyMem(DevPath, Buffer+6+DescriptionSize, LoadOption->FilePathListLength);\r
DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);\r
}\r
- } else {\r
- DevPath = NULL;\r
- DevPathString = NULL;\r
}\r
ShellPrintHiiEx(\r
-1,\r
gShellBcfgHiiHandle,\r
LoopVar,\r
VariableName,\r
- (CHAR16*)(Buffer+6),\r
+ Description,\r
DevPathString,\r
- (StrSize((CHAR16*)(Buffer+6)) + *(UINT16*)(Buffer+4) + 6) <= BufferSize?L'N':L'Y');\r
+ (DescriptionSize + LoadOption->FilePathListLength + 6) <= BufferSize?L'N':L'Y');\r
if (VerboseOutput) {\r
- for (LoopVar2 = (StrSize((CHAR16*)(Buffer+6)) + *(UINT16*)(Buffer+4) + 6);LoopVar2<BufferSize;LoopVar2++){\r
+ for (LoopVar2 = (DescriptionSize + LoadOption->FilePathListLength + 6);LoopVar2<BufferSize;LoopVar2++){\r
ShellPrintEx(\r
-1,\r
-1,\r
L"\r\n");\r
}\r
\r
+Cleanup:\r
if (Buffer != NULL) {\r
FreePool(Buffer);\r
}\r
FreePool(DevPathString);\r
}\r
}\r
- return (SHELL_SUCCESS);\r
+ return (Errors > 0) ? SHELL_INVALID_PARAMETER : SHELL_SUCCESS;\r
}\r
\r
/**\r
Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);\r
CurrentOperation.Number1 = (UINT16)Intermediate;\r
if (CurrentOperation.Number1 >= Count){\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), L"bcfg", gShellBcfgHiiHandle, Count); \r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellBcfgHiiHandle, L"bcfg", Count); \r
ShellStatus = SHELL_INVALID_PARAMETER;\r
} else {\r
CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);\r