From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D7FD28194D for ; Sun, 8 Jan 2017 22:17:19 -0800 (PST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP; 08 Jan 2017 22:17:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,339,1477983600"; d="scan'208";a="51006688" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga005.fm.intel.com with ESMTP; 08 Jan 2017 22:17:19 -0800 Received: from fmsmsx157.amr.corp.intel.com (10.18.116.73) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 8 Jan 2017 22:17:19 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX157.amr.corp.intel.com (10.18.116.73) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 8 Jan 2017 22:17:19 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.59]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.204]) with mapi id 14.03.0248.002; Mon, 9 Jan 2017 14:17:15 +0800 From: "Ni, Ruiyu" To: "Kinney, Michael D" , "edk2-devel@lists.01.org" CC: "Carsey, Jaben" , "Kinney, Michael D" Thread-Topic: [edk2] [Patch] ShellPkg/Shell: Add double quotes to args with white space Thread-Index: AQHSaSROaYFFe22lf0m4hqQjnxw6W6EvrTBw Date: Mon, 9 Jan 2017 06:17:15 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5B878DDC@SHSMSX104.ccr.corp.intel.com> References: <1483820771-22460-1-git-send-email-michael.d.kinney@intel.com> In-Reply-To: <1483820771-22460-1-git-send-email-michael.d.kinney@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch] ShellPkg/Shell: Add double quotes to args with white space X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Jan 2017 06:17:20 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Mike, According to the wording below copied from Shell spec, quotes are removed b= efore saving To Argv. "Argv Points to an Argc-element array of points to null-terminated strings containing the command-line parameters. The first entry in the array is always the full file path of the executable. Any quotation marks that were used to preserve whitespace have been removed." "Double-quotation marks that surround arguments are stripped before they ar= e passed to the entry point of a shell application. For more information, see= the Argv member of the EFI_SHELL_PARAMETERS_PROTOCOL." Thanks/Ray > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Michael Kinney > Sent: Sunday, January 8, 2017 4:26 AM > To: edk2-devel@lists.01.org > Cc: Carsey, Jaben ; Ni, Ruiyu ; > Kinney, Michael D > Subject: [edk2] [Patch] ShellPkg/Shell: Add double quotes to args with wh= ite > space >=20 > https://bugzilla.tianocore.org/show_bug.cgi?id=3D332 >=20 > When the ShellLib ShellExecute() API or the Shell Protocol Execute() API = are > used to execute a command, the arguments are parsed to produce the > Argc/Argv list in the Shell Parameters Protocol and double quotes are > removed from arguments that are surrounded by double quotes. This is the > required behavior of the Shell Parameters Protocol. >=20 > The ProcessCommandLine() function in the shell implementation uses the > Argc/Argv list from the Shell Parameters Protocol to assemble a new > command line, but the double quotes that may have been originally present > for an argument are not preserved. >=20 > ProcessCommandLine() is updated to check if an argument added to the > generated command line contains one or more white space characters, and i= f > it does, double quotes are added around the argument. >=20 > Cc: Jaben Carsey > Cc: Ruiyu Ni > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Michael D Kinney > --- > ShellPkg/Application/Shell/Shell.c | 64 > +++++++++++++++++++++++++++++++++----- > 1 file changed, 56 insertions(+), 8 deletions(-) >=20 > diff --git a/ShellPkg/Application/Shell/Shell.c > b/ShellPkg/Application/Shell/Shell.c > index b39d81d..29e68db 100644 > --- a/ShellPkg/Application/Shell/Shell.c > +++ b/ShellPkg/Application/Shell/Shell.c > @@ -1042,11 +1042,31 @@ ProcessCommandLine( > continue; > } >=20 > - ShellInfoObject.ShellInitSettings.FileName =3D > AllocateCopyPool(StrSize(CurrentArg), CurrentArg); > + ShellInfoObject.ShellInitSettings.FileName =3D NULL; > + Size =3D 0; > + // > + // If first argument contains a space, then add double quotes befo= re the > argument > + // > + if (StrStr (CurrentArg, L" ") !=3D NULL) { > + StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileName, &Size, = L"\"", > 0); > + if (ShellInfoObject.ShellInitSettings.FileName =3D=3D NULL) { > + return (EFI_OUT_OF_RESOURCES); > + } > + } > + StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileName, &Size, > + CurrentArg, 0); > if (ShellInfoObject.ShellInitSettings.FileName =3D=3D NULL) { > return (EFI_OUT_OF_RESOURCES); > } > // > + // If first argument contains a space, then add double quotes afte= r the > argument > + // > + if (StrStr (CurrentArg, L" ") !=3D NULL) { > + StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileName, &Size, = L"\"", > 0); > + if (ShellInfoObject.ShellInitSettings.FileName =3D=3D NULL) { > + return (EFI_OUT_OF_RESOURCES); > + } > + } > + // > // We found `file-name`. > // > ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup =3D 1; @= @ - > 1055,13 +1075,28 @@ ProcessCommandLine( > // Add `file-name-options` > for (Size =3D 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; Lo= opVar++) { > ASSERT((ShellInfoObject.ShellInitSettings.FileOptions =3D=3D NUL= L && Size > =3D=3D 0) || (ShellInfoObject.ShellInitSettings.FileOptions !=3D NULL)); > - StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions, > - &Size, > - L" ", > - 0); > - if (ShellInfoObject.ShellInitSettings.FileOptions =3D=3D NULL) { > - SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileName= ); > - return (EFI_OUT_OF_RESOURCES); > + // > + // Add a space between arguments > + // > + if (ShellInfoObject.ShellInitSettings.FileOptions !=3D NULL) { > + StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions, &S= ize, L" > ", 0); > + if (ShellInfoObject.ShellInitSettings.FileOptions =3D=3D NULL)= { > + SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileNa= me); > + return (EFI_OUT_OF_RESOURCES); > + } > + } > + // > + // If an argumnent contains a space, then add double quotes befo= re the > argument > + // > + if (StrStr (gEfiShellParametersProtocol->Argv[LoopVar], L" ") != =3D NULL) { > + StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions, > + &Size, > + L"\"", > + 0); > + if (ShellInfoObject.ShellInitSettings.FileOptions =3D=3D NULL)= { > + SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileNa= me); > + return (EFI_OUT_OF_RESOURCES); > + } > } > StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions, > &Size, > @@ -1071,6 +1106,19 @@ ProcessCommandLine( > SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileName= ); > return (EFI_OUT_OF_RESOURCES); > } > + // > + // If an argumnent contains a space, then add double quotes afte= r the > argument > + // > + if (StrStr (gEfiShellParametersProtocol->Argv[LoopVar], L" ") != =3D NULL) { > + StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions, > + &Size, > + L"\"", > + 0); > + if (ShellInfoObject.ShellInitSettings.FileOptions =3D=3D NULL)= { > + SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileNa= me); > + return (EFI_OUT_OF_RESOURCES); > + } > + } > } > } > } > -- > 2.6.3.windows.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel