From e9d19a80afe61145433fe7f7f4c563c355c5c461 Mon Sep 17 00:00:00 2001 From: Chris Phillips Date: Fri, 4 Apr 2014 13:45:36 +0000 Subject: [PATCH] ShellPkg: Fix command-line parsing to start with Argv[0] when comparing passed-in options Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Chris Phillips Reviewed-By: Olivier Martin Reviewed-by: Jaben Carsey git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15432 6f19259b-4bc3-4df7-8a09-765794883524 --- ShellPkg/Application/Shell/Shell.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index fa7201642a..056d66d09e 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -835,9 +835,13 @@ ProcessCommandLine( ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit = FALSE; ShellInfoObject.ShellInitSettings.Delay = 5; - // Start LoopVar at 1 to ignore Argv[0] which is the name of this binary - // (probably "Shell.efi") - for (LoopVar = 1 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) { + // + // Start LoopVar at 0 to parse only optional arguments at Argv[0] + // and parse other parameters from Argv[1]. This is for use case that + // UEFI Shell boot option is created, and OptionalData is provided + // that starts with shell command-line options. + // + for (LoopVar = 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) { CurrentArg = gEfiShellParametersProtocol->Argv[LoopVar]; if (UnicodeCollation->StriColl ( UnicodeCollation, @@ -925,6 +929,13 @@ ProcessCommandLine( ); return EFI_INVALID_PARAMETER; } else { + // + // First argument should be Shell.efi image name + // + if (LoopVar == 0) { + continue; + } + ShellInfoObject.ShellInitSettings.FileName = AllocateZeroPool(StrSize(CurrentArg)); if (ShellInfoObject.ShellInitSettings.FileName == NULL) { return (EFI_OUT_OF_RESOURCES); -- 2.39.2