summaryrefslogtreecommitdiff
path: root/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c
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/UefiShellInstall1CommandsLib/Bcfg.c
parent15f8eef78458da1d6270d79724f8e91b56a35371 (diff)
downloadedk2-platforms-37a4164af3a9f09f5e8afa3d639fcb514fe92ce7.tar.xz
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/UefiShellInstall1CommandsLib/Bcfg.c')
-rw-r--r--ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c70
1 files changed, 42 insertions, 28 deletions
diff --git a/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c b/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c
index a7893f5eee..bb81df59cc 100644
--- a/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c
+++ b/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c
@@ -665,23 +665,34 @@ BcfgMoveInstall1(
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,
@@ -1142,6 +1153,7 @@ ShellCommandRunBcfgInstall (
BGFG_OPERATION CurrentOperation;
UINTN Length;
UINT64 Intermediate;
+ UINT16 Count;
Length = 0;
ProblemParam = NULL;
@@ -1228,6 +1240,8 @@ ShellCommandRunBcfgInstall (
}
}
+ Count = (UINT16) (Length / sizeof(CurrentOperation.Order[0]));
+
//
// large block to read the type of operation and verify parameter types for the info.
//
@@ -1312,8 +1326,8 @@ ShellCommandRunBcfgInstall (
} 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), gShellInstall1HiiHandle, Length / sizeof(CurrentOperation.Order[0]));
+ if (CurrentOperation.Number1 > Count){
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellInstall1HiiHandle, Count);
ShellStatus = SHELL_INVALID_PARAMETER;
}
}
@@ -1330,24 +1344,24 @@ ShellCommandRunBcfgInstall (
} 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), gShellInstall1HiiHandle, 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), gShellInstall1HiiHandle, CurrentParam);
+ if (CurrentOperation.Number1 > Count){
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellInstall1HiiHandle, 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), gShellInstall1HiiHandle, 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), gShellInstall1HiiHandle, 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), gShellInstall1HiiHandle, Count);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
}
}
} else {
@@ -1364,7 +1378,7 @@ ShellCommandRunBcfgInstall (
case BcfgTypeDump:
ShellStatus = BcfgDisplayDumpInstall1(
CurrentOperation.Target == BcfgTargetBootOrder?L"Boot":L"Driver",
- Length / sizeof(CurrentOperation.Order[0]),
+ Count,
CurrentOperation.Order,
ShellCommandLineGetFlag(Package, L"-v"));
break;
@@ -1372,7 +1386,7 @@ ShellCommandRunBcfgInstall (
ShellStatus = BcfgMoveInstall1(
CurrentOperation.Target,
CurrentOperation.Order,
- Length / sizeof(CurrentOperation.Order[0]),
+ Count,
CurrentOperation.Number1,
CurrentOperation.Number2);
break;
@@ -1380,7 +1394,7 @@ ShellCommandRunBcfgInstall (
ShellStatus = BcfgRemoveInstall1(
CurrentOperation.Target,
CurrentOperation.Order,
- Length / sizeof(CurrentOperation.Order[0]),
+ Count,
CurrentOperation.Number1);
break;
case BcfgTypeAdd:
@@ -1391,7 +1405,7 @@ ShellCommandRunBcfgInstall (
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),
@@ -1401,7 +1415,7 @@ ShellCommandRunBcfgInstall (
ShellStatus = BcfgAddOptInstall1(
CurrentOperation.OptData,
CurrentOperation.Order,
- Length / sizeof(CurrentOperation.Order[0]),
+ Count,
CurrentOperation.Target);
break;
default: