From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 278418032A for ; Mon, 6 Mar 2017 10:27:30 -0800 (PST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP; 06 Mar 2017 10:27:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,254,1484035200"; d="scan'208";a="941209873" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga003.jf.intel.com with ESMTP; 06 Mar 2017 10:27:29 -0800 Received: from fmsmsx120.amr.corp.intel.com (10.18.124.208) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 6 Mar 2017 10:27:29 -0800 Received: from fmsmsx103.amr.corp.intel.com ([169.254.2.47]) by fmsmsx120.amr.corp.intel.com ([169.254.15.204]) with mapi id 14.03.0248.002; Mon, 6 Mar 2017 10:27:29 -0800 From: "Carsey, Jaben" To: Vladimir Olovyannikov , "edk2-devel@lists.01.org" , "Ni, Ruiyu" CC: "Carsey, Jaben" Thread-Topic: [PATCH] ShellPkg: Fix Shell not able to run startup.nsh from first location Thread-Index: AQHSlqWx1MKUEtENE0Oyi/ytNBEnOaGIISgg Date: Mon, 6 Mar 2017 18:27:28 +0000 Message-ID: References: <1488824074-5202-1-git-send-email-vladimir.olovyannikov@broadcom.com> In-Reply-To: <1488824074-5202-1-git-send-email-vladimir.olovyannikov@broadcom.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMTNmZDM1ZWUtYjZjNS00M2U3LWEzYjgtNzZjNWViM2FiMGI1IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6IlE4a0Nyc2V1dlk4TzJXOGVtdXlXd2FvcjBDOUYzaU1uNXhySEk0MkMwbEU9In0= x-ctpclassification: CTP_IC x-originating-ip: [10.1.200.108] MIME-Version: 1.0 Subject: Re: [PATCH] ShellPkg: Fix Shell not able to run startup.nsh from first location 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, 06 Mar 2017 18:27:30 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Looks good to me. =20 Ray? > -----Original Message----- > From: Vladimir Olovyannikov [mailto:vladimir.olovyannikov@broadcom.com] > Sent: Monday, March 06, 2017 10:15 AM > To: edk2-devel@lists.01.org; Carsey, Jaben ; Ni, > Ruiyu > Cc: Vladimir Olovyannikov > Subject: [PATCH] ShellPkg: Fix Shell not able to run startup.nsh from fir= st > location > Importance: High >=20 > If startup.nsh is placed into first location (embedded into the firmware > image), > and the current directory has not been set (Internal Shell has just start= ed), > Shell cannot execute startup because of the bug in the DoStartupScript: > after finding the correct path of the startup.nsh from the "First locatio= n" > and opening the file, and getting of the file handle, the correct path is > forgotten, and then RunScriptFile() receives just the name of the file > (from mStartupScript ariable). > It then attempts to check if this is a file with ShellIsFile() which fail= s > with "EFI_INVALID_PARAMETER" (current directory is NULL, so it cannot get > fully qualified file name), which causes Shell to exit and unload. > This patch fixes the issue. > --- > ShellPkg/Application/Shell/Shell.c | 21 +++++++++++++++------ > 1 file changed, 15 insertions(+), 6 deletions(-) >=20 > diff --git a/ShellPkg/Application/Shell/Shell.c > b/ShellPkg/Application/Shell/Shell.c > index 731ba187e4d9..4967fe598448 100644 > --- a/ShellPkg/Application/Shell/Shell.c > +++ b/ShellPkg/Application/Shell/Shell.c > @@ -1162,6 +1162,7 @@ DoStartupScript( > Key.UnicodeChar =3D CHAR_NULL; > Key.ScanCode =3D 0; > FileHandle =3D NULL; > + FileStringPath =3D NULL; >=20 > if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup && > ShellInfoObject.ShellInitSettings.FileName !=3D NULL) { > // > @@ -1228,7 +1229,6 @@ DoStartupScript( > // > MapName =3D ShellInfoObject.NewEfiShellProtocol- > >GetMapFromDevicePath(&ImagePath); > if (MapName !=3D NULL) { > - FileStringPath =3D NULL; > NewSize =3D 0; > FileStringPath =3D StrnCatGrow(&FileStringPath, &NewSize, MapName, 0= ); > if (FileStringPath =3D=3D NULL) { > @@ -1242,10 +1242,10 @@ DoStartupScript( > PathRemoveLastItem(FileStringPath); > FileStringPath =3D StrnCatGrow(&FileStringPath, &NewSize, mStartup= Script, > 0); > Status =3D ShellInfoObject.NewEfiShellProtocol- > >OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ); > - FreePool(FileStringPath); > } > } > if (EFI_ERROR(Status)) { > + SHELL_FREE_NON_NULL (FileStringPath); > NamePath =3D FileDevicePath (NULL, mStartupScript); > NewPath =3D AppendDevicePathNode (ImagePath, NamePath); > FreePool(NamePath); > @@ -1254,15 +1254,21 @@ DoStartupScript( > // Try the location > // > Status =3D InternalOpenFileDevicePath(NewPath, &FileHandle, > EFI_FILE_MODE_READ, 0); > - FreePool(NewPath); > + if (!EFI_ERROR (Status)) { > + FileStringPath =3D gEfiShellProtocol- > >GetFilePathFromDevicePath(NewPath); > + if (FileStringPath =3D=3D NULL) { > + Status =3D EFI_OUT_OF_RESOURCES; > + } > + } > + FreePool (NewPath); > } > // > // If we got a file, run it > // > if (!EFI_ERROR(Status) && FileHandle !=3D NULL) { > - Status =3D RunScriptFile (mStartupScript, FileHandle, L"", > ShellInfoObject.NewShellParametersProtocol); > - ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle); > + Status =3D RunScriptFile (FileStringPath, FileHandle, L"", > ShellInfoObject.NewShellParametersProtocol); > } else { > + SHELL_FREE_NON_NULL (FileStringPath); > FileStringPath =3D ShellFindFilePath(mStartupScript); > if (FileStringPath =3D=3D NULL) { > // > @@ -1272,10 +1278,13 @@ DoStartupScript( > ASSERT(FileHandle =3D=3D NULL); > } else { > Status =3D RunScriptFile(FileStringPath, NULL, L"", > ShellInfoObject.NewShellParametersProtocol); > - FreePool(FileStringPath); > } > } >=20 > + SHELL_FREE_NON_NULL (FileStringPath); > + if (FileHandle !=3D NULL) { > + ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle); > + } >=20 > return (Status); > } > -- > 1.9.1