summaryrefslogtreecommitdiff
path: root/ShellPkg/Library/UefiShellDebug1CommandsLib
diff options
context:
space:
mode:
authorJaben Carsey <jaben.carsey@intel.com>2014-09-04 20:55:29 +0000
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2014-09-04 20:55:29 +0000
commit37a4164af3a9f09f5e8afa3d639fcb514fe92ce7 (patch)
tree68b094f748d156394d1447917d897dbbad1eeab1 /ShellPkg/Library/UefiShellDebug1CommandsLib
parent15f8eef78458da1d6270d79724f8e91b56a35371 (diff)
ShellPkg: Update BCFG command for correct use and errors on moving
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Tapan Shah <tapandshah@hp.com> Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16060 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg/Library/UefiShellDebug1CommandsLib')
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c70
1 files changed, 42 insertions, 28 deletions
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c
index 483aa5855e..93ef73d074 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c
@@ -667,23 +667,34 @@ BcfgMoveDebug1(
IN CONST UINT16 *CurrentOrder,
IN CONST UINTN OrderCount,
IN CONST UINT16 OldLocation,
- IN CONST UINT16 NewLocation
+ IN UINT16 NewLocation
)
{
UINT16 *NewOrder;
EFI_STATUS Status;
UINT16 Temp;
- NewOrder = AllocateZeroPool(OrderCount*sizeof(CurrentOrder[0]));
- ASSERT(NewOrder != NULL);
+ NewOrder = AllocateCopyPool(OrderCount*sizeof(CurrentOrder[0]), CurrentOrder);
+ if (NewOrder == NULL) {
+ return (SHELL_OUT_OF_RESOURCES);
+ }
+
+ //
+ // correct the new location
+ //
+ if (NewLocation >= OrderCount) {
+ if (OrderCount > 0) {
+ NewLocation = (UINT16)OrderCount - 1;
+ } else {
+ NewLocation = 0;
+ }
+ }
Temp = CurrentOrder[OldLocation];
- CopyMem(NewOrder, CurrentOrder, OrderCount*sizeof(CurrentOrder[0]));
CopyMem(NewOrder+OldLocation, NewOrder+OldLocation+1, (OrderCount - OldLocation - 1)*sizeof(CurrentOrder[0]));
CopyMem(NewOrder+NewLocation+1, NewOrder+NewLocation, (OrderCount - NewLocation - 1)*sizeof(CurrentOrder[0]));
NewOrder[NewLocation] = Temp;
-
Status = gRT->SetVariable(
Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
(EFI_GUID*)&gEfiGlobalVariableGuid,
@@ -1146,6 +1157,7 @@ ShellCommandRunBcfg (
BGFG_OPERATION CurrentOperation;
UINTN Length;
UINT64 Intermediate;
+ UINT16 Count;
Length = 0;
ProblemParam = NULL;
@@ -1232,6 +1244,8 @@ ShellCommandRunBcfg (
}
}
+ Count = (UINT16) (Length / sizeof(CurrentOperation.Order[0]));
+
//
// large block to read the type of operation and verify parameter types for the info.
//
@@ -1316,8 +1330,8 @@ ShellCommandRunBcfg (
} else {
Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);
CurrentOperation.Number1 = (UINT16)Intermediate;
- if (CurrentOperation.Number1 > (Length / sizeof(CurrentOperation.Order[0]))){
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellDebug1HiiHandle, Length / sizeof(CurrentOperation.Order[0]));
+ if (CurrentOperation.Number1 > Count){
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellDebug1HiiHandle, Count);
ShellStatus = SHELL_INVALID_PARAMETER;
}
}
@@ -1334,24 +1348,24 @@ ShellCommandRunBcfg (
} else {
Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);
CurrentOperation.Number1 = (UINT16)Intermediate;
- if (CurrentOperation.Number1 > (Length / sizeof(CurrentOperation.Order[0]))){
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellDebug1HiiHandle, Length / sizeof(CurrentOperation.Order[0]));
- ShellStatus = SHELL_INVALID_PARAMETER;
- }
- CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);
- if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber(CurrentParam, TRUE, FALSE)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);
+ if (CurrentOperation.Number1 > Count){
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellDebug1HiiHandle, Count);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);
- CurrentOperation.Number2 = (UINT16)Intermediate;
- }
- if (CurrentOperation.Number2 == CurrentOperation.Number1
- ||CurrentOperation.Number1 > (Length / sizeof(CurrentOperation.Order[0]))
- ||CurrentOperation.Number2 > (Length / sizeof(CurrentOperation.Order[0]))
- ){
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellDebug1HiiHandle, Length / sizeof(CurrentOperation.Order[0]));
- ShellStatus = SHELL_INVALID_PARAMETER;
+ CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);
+ if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber(CurrentParam, TRUE, FALSE)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);
+ CurrentOperation.Number2 = (UINT16)Intermediate;
+ }
+ if (CurrentOperation.Number2 == CurrentOperation.Number1
+ ||CurrentOperation.Number2 >= Count
+ ){
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellDebug1HiiHandle, Count);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
}
}
} else {
@@ -1368,7 +1382,7 @@ ShellCommandRunBcfg (
case BcfgTypeDump:
ShellStatus = BcfgDisplayDumpDebug1(
CurrentOperation.Target == BcfgTargetBootOrder?L"Boot":L"Driver",
- Length / sizeof(CurrentOperation.Order[0]),
+ Count,
CurrentOperation.Order,
ShellCommandLineGetFlag(Package, L"-v"));
break;
@@ -1376,7 +1390,7 @@ ShellCommandRunBcfg (
ShellStatus = BcfgMoveDebug1(
CurrentOperation.Target,
CurrentOperation.Order,
- Length / sizeof(CurrentOperation.Order[0]),
+ Count,
CurrentOperation.Number1,
CurrentOperation.Number2);
break;
@@ -1384,7 +1398,7 @@ ShellCommandRunBcfg (
ShellStatus = BcfgRemoveDebug1(
CurrentOperation.Target,
CurrentOperation.Order,
- Length / sizeof(CurrentOperation.Order[0]),
+ Count,
CurrentOperation.Number1);
break;
case BcfgTypeAdd:
@@ -1395,7 +1409,7 @@ ShellCommandRunBcfg (
CurrentOperation.FileName,
CurrentOperation.Description==NULL?L"":CurrentOperation.Description,
CurrentOperation.Order,
- Length / sizeof(CurrentOperation.Order[0]),
+ Count,
CurrentOperation.Target,
(BOOLEAN)(CurrentOperation.Type == BcfgTypeAddh),
(BOOLEAN)(CurrentOperation.Type == BcfgTypeAddp),
@@ -1405,7 +1419,7 @@ ShellCommandRunBcfg (
ShellStatus = BcfgAddOptDebug1(
CurrentOperation.OptData,
CurrentOperation.Order,
- Length / sizeof(CurrentOperation.Order[0]),
+ Count,
CurrentOperation.Target);
break;
default: