ShellPkg: Don't strip positional parameters of quotation marks.

Per Shell SPEC 2.1 'Double-quotation marks that surround arguments are not stripped in positional parameters'. This patch makes Shell implementation to follow SPEC.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <shumin.qiu@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18742 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Qiu Shumin
2015-11-09 02:29:31 +00:00
committed by shenshushi
parent 3ec97ca490
commit d1c275c651
5 changed files with 80 additions and 48 deletions

View File

@ -74,10 +74,12 @@ FindEndOfParameter(
This will also remove all remaining ^ characters after processing.
@param[in, out] Walker pointer to string of command line. Adjusted to
reminaing command line on return
@param[in, out] TempParameter pointer to string of command line item extracted.
@param[in] Length buffer size of TempParameter.
@param[in, out] Walker pointer to string of command line. Adjusted to
reminaing command line on return
@param[in, out] TempParameter pointer to string of command line item extracted.
@param[in] Length buffer size of TempParameter.
@param[in] StripQuotation if TRUE then strip the quotation marks surrounding
the parameters.
@return EFI_INALID_PARAMETER A required parameter was NULL or pointed to a NULL or empty string.
@return EFI_NOT_FOUND A closing " could not be found on the specified string
@ -87,7 +89,8 @@ EFIAPI
GetNextParameter(
IN OUT CHAR16 **Walker,
IN OUT CHAR16 **TempParameter,
IN CONST UINTN Length
IN CONST UINTN Length,
IN BOOLEAN StripQuotation
)
{
CONST CHAR16 *NextDelim;
@ -161,7 +164,11 @@ DEBUG_CODE_END();
//
// eliminate the unescaped quote
//
CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));
if (StripQuotation) {
CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));
} else{
NextDelim++;
}
}
}
@ -178,9 +185,11 @@ DEBUG_CODE_END();
All special character processing (alias, environment variable, redirection,
etc... must be complete before calling this API.
@param[in] CommandLine String of command line to parse
@param[in, out] Argv pointer to array of strings; one for each parameter
@param[in, out] Argc pointer to number of strings in Argv array
@param[in] CommandLine String of command line to parse
@param[in] StripQuotation if TRUE then strip the quotation marks surrounding
the parameters.
@param[in, out] Argv pointer to array of strings; one for each parameter
@param[in, out] Argc pointer to number of strings in Argv array
@return EFI_SUCCESS the operation was sucessful
@return EFI_OUT_OF_RESOURCES a memory allocation failed.
@ -189,8 +198,9 @@ EFI_STATUS
EFIAPI
ParseCommandLineToArgs(
IN CONST CHAR16 *CommandLine,
IN OUT CHAR16 ***Argv,
IN OUT UINTN *Argc
IN BOOLEAN StripQuotation,
IN OUT CHAR16 ***Argv,
IN OUT UINTN *Argc
)
{
UINTN Count;
@ -228,7 +238,7 @@ ParseCommandLineToArgs(
; Walker != NULL && *Walker != CHAR_NULL
; Count++
) {
if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size))) {
if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size, TRUE))) {
break;
}
}
@ -246,7 +256,7 @@ ParseCommandLineToArgs(
Walker = (CHAR16*)NewCommandLine;
while(Walker != NULL && *Walker != CHAR_NULL) {
SetMem16(TempParameter, Size, CHAR_NULL);
if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size))) {
if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size, StripQuotation))) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
@ -375,6 +385,7 @@ CreatePopulateInstallShellParametersProtocol (
// Populate Argc and Argv
//
Status = ParseCommandLineToArgs(FullCommandLine,
TRUE,
&(*NewShellParameters)->Argv,
&(*NewShellParameters)->Argc);
@ -1369,6 +1380,7 @@ RestoreStdInStdOutStdErr (
@param[in, out] ShellParameters Pointer to parameter structure to modify.
@param[in] NewCommandLine The new command line to parse and use.
@param[in] Type The type of operation.
@param[out] OldArgv Pointer to old list of parameters.
@param[out] OldArgc Pointer to old number of items in Argv list.
@ -1380,11 +1392,15 @@ EFIAPI
UpdateArgcArgv(
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
IN CONST CHAR16 *NewCommandLine,
IN SHELL_OPERATION_TYPES Type,
OUT CHAR16 ***OldArgv OPTIONAL,
OUT UINTN *OldArgc OPTIONAL
)
{
BOOLEAN StripParamQuotation;
ASSERT(ShellParameters != NULL);
StripParamQuotation = TRUE;
if (OldArgc != NULL) {
*OldArgc = ShellParameters->Argc;
@ -1393,7 +1409,15 @@ UpdateArgcArgv(
*OldArgv = ShellParameters->Argv;
}
return (ParseCommandLineToArgs(NewCommandLine, &(ShellParameters->Argv), &(ShellParameters->Argc)));
if (Type == Script_File_Name) {
StripParamQuotation = FALSE;
}
return ParseCommandLineToArgs( NewCommandLine,
StripParamQuotation,
&(ShellParameters->Argv),
&(ShellParameters->Argc)
);
}
/**