ShellPkg: pre-verify split commands
This makes sure that all parts of commands split via pipe operation are valid before starting. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jaben Carsey <jaben.carsey@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15011 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
12a27a6d81
commit
6bd644638d
|
@ -1596,6 +1596,96 @@ GetOperationType(
|
||||||
return (UNKNOWN_INVALID);
|
return (UNKNOWN_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
IsValidSplit(
|
||||||
|
IN CONST CHAR16 *CmdLine
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CHAR16 *Temp;
|
||||||
|
CHAR16 *FirstParameter;
|
||||||
|
CHAR16 *TempWalker;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
Temp = NULL;
|
||||||
|
|
||||||
|
Temp = StrnCatGrow(&Temp, NULL, CmdLine, 0);
|
||||||
|
if (Temp == NULL) {
|
||||||
|
return (EFI_OUT_OF_RESOURCES);
|
||||||
|
}
|
||||||
|
|
||||||
|
FirstParameter = StrStr(Temp, L"|");
|
||||||
|
if (FirstParameter != NULL) {
|
||||||
|
*FirstParameter = CHAR_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
FirstParameter = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Process the command line
|
||||||
|
//
|
||||||
|
Status = ProcessCommandLineToFinal(&Temp);
|
||||||
|
|
||||||
|
if (!EFI_ERROR(Status)) {
|
||||||
|
FirstParameter = AllocateZeroPool(StrSize(CmdLine));
|
||||||
|
if (FirstParameter == NULL) {
|
||||||
|
SHELL_FREE_NON_NULL(Temp);
|
||||||
|
return (EFI_OUT_OF_RESOURCES);
|
||||||
|
}
|
||||||
|
TempWalker = (CHAR16*)Temp;
|
||||||
|
GetNextParameter(&TempWalker, &FirstParameter);
|
||||||
|
|
||||||
|
if (GetOperationType(FirstParameter) == UNKNOWN_INVALID) {
|
||||||
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
|
||||||
|
SetLastError(SHELL_NOT_FOUND);
|
||||||
|
Status = EFI_NOT_FOUND;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SHELL_FREE_NON_NULL(Temp);
|
||||||
|
SHELL_FREE_NON_NULL(FirstParameter);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Determine if a command line contains with a split contains only valid commands
|
||||||
|
|
||||||
|
@param[in] CmdLine The command line to parse.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS CmdLine has only valid commands, application, or has no split.
|
||||||
|
@retval EFI_ABORTED CmdLine has at least one invalid command or application.
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
VerifySplit(
|
||||||
|
IN CONST CHAR16 *CmdLine
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CONST CHAR16 *TempSpot;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Verify up to the pipe or end character
|
||||||
|
//
|
||||||
|
Status = IsValidSplit(CmdLine);
|
||||||
|
if (EFI_ERROR(Status)) {
|
||||||
|
return (Status);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// If this was the only item, then get out
|
||||||
|
//
|
||||||
|
if (!ContainsSplit(CmdLine)) {
|
||||||
|
return (EFI_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// recurse to verify the next item
|
||||||
|
//
|
||||||
|
TempSpot = FindSplit(CmdLine)+1;
|
||||||
|
return (VerifySplit(TempSpot));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Process a split based operation.
|
Process a split based operation.
|
||||||
|
|
||||||
|
@ -1613,6 +1703,11 @@ ProcessNewSplitCommandLine(
|
||||||
SPLIT_LIST *Split;
|
SPLIT_LIST *Split;
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
Status = VerifySplit(CmdLine);
|
||||||
|
if (EFI_ERROR(Status)) {
|
||||||
|
return (Status);
|
||||||
|
}
|
||||||
|
|
||||||
Split = NULL;
|
Split = NULL;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -1728,7 +1823,7 @@ DoHelpUpdate(
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
SetLastError(
|
SetLastError(
|
||||||
IN CONST UINT64 ErrorCode
|
IN CONST SHELL_STATUS ErrorCode
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CHAR16 LeString[19];
|
CHAR16 LeString[19];
|
||||||
|
@ -1943,7 +2038,7 @@ RunCommandOrFile(
|
||||||
//
|
//
|
||||||
if (!EFI_ERROR(ShellIsDirectory(CommandWithPath))) {
|
if (!EFI_ERROR(ShellIsDirectory(CommandWithPath))) {
|
||||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
|
||||||
SetLastError(EFI_NOT_FOUND);
|
SetLastError(SHELL_NOT_FOUND);
|
||||||
}
|
}
|
||||||
switch (Type) {
|
switch (Type) {
|
||||||
case SCRIPT_FILE_NAME:
|
case SCRIPT_FILE_NAME:
|
||||||
|
@ -2129,7 +2224,7 @@ RunCommand(
|
||||||
// Whatever was typed, it was invalid.
|
// Whatever was typed, it was invalid.
|
||||||
//
|
//
|
||||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
|
||||||
SetLastError(EFI_NOT_FOUND);
|
SetLastError(SHELL_NOT_FOUND);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,6 +132,32 @@ typedef enum {
|
||||||
UNKNOWN_INVALID
|
UNKNOWN_INVALID
|
||||||
} SHELL_OPERATION_TYPES;
|
} SHELL_OPERATION_TYPES;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Converts the command line to it's post-processed form. this replaces variables and alias' per UEFI Shell spec.
|
||||||
|
|
||||||
|
@param[in,out] CmdLine pointer to the command line to update
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The operation was successful
|
||||||
|
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
|
||||||
|
@return some other error occured
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
ProcessCommandLineToFinal(
|
||||||
|
IN OUT CHAR16 **CmdLine
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Function to update the shell variable "lasterror"
|
||||||
|
|
||||||
|
@param[in] ErrorCode the error code to put into lasterror
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
SetLastError(
|
||||||
|
IN CONST SHELL_STATUS ErrorCode
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Sets all the alias' that were registered with the ShellCommandLib library.
|
Sets all the alias' that were registered with the ShellCommandLib library.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue