From nobody Sat Nov 2 12:29:57 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1488824148170192.36447589768625; Mon, 6 Mar 2017 10:15:48 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 557398032E; Mon, 6 Mar 2017 10:15:45 -0800 (PST) Received: from mail-qk0-x22c.google.com (mail-qk0-x22c.google.com [IPv6:2607:f8b0:400d:c09::22c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 367E18032A for ; Mon, 6 Mar 2017 10:15:44 -0800 (PST) Received: by mail-qk0-x22c.google.com with SMTP id y76so36103140qkb.0 for ; Mon, 06 Mar 2017 10:15:44 -0800 (PST) Received: from LBRMN-LNXUB114.ric.broadcom.com ([192.19.224.250]) by smtp.gmail.com with ESMTPSA id p19sm1707206qtp.36.2017.03.06.10.15.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Mar 2017 10:15:42 -0800 (PST) X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:contributed-under:signed-off-by; bh=qs+V+wLzekQzyQFn0TmS5Q61Tb/KCyLxgEc3fnrPhCg=; b=ARBwk8+aZn+q3HRtDADbADMMCVelRZjQ0U0vHA7F4FJleuN4IWi03mwoaxIAR1/E9d kv4aFwDUIl50lflabY8MeE4TMo8LaJFgPv1EAal8SnNzMEjFkPPaGM1CNBFO+BW9zFX/ q/tZG6cCgcWKlcWGg/gf5VEfsAQZ9gGEz2phI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id :contributed-under:signed-off-by; bh=qs+V+wLzekQzyQFn0TmS5Q61Tb/KCyLxgEc3fnrPhCg=; b=sF9zQdnbWD4N6nQMTTC6Bv2vLJQVRjeOtmitGXYt566ClQZhS6jyF3MKBIlXIh05of 6fwZ6Qq87C3HGKtVkWTToBXtzYSl+tCFbgl29p3480tV/0UbeYCNx4Glq3rVcjnKIF6Z oR7e61Cm0Fhwmbdyj4yuYI1AexWwrmWlw4dD4KOzhupMkkHhX/JJESRTxqu0w6Vw6JWy nhSE5NrpRCNo+vGqVfdVg6lTCR7kvyTvjVQoje5Miq5wfs8TsH7W/6LfXtlSROKSUJm1 D4y36Gi+jt9vcC1YslD6qqZ152221ObBqxV5tqLx4UwcWKbGYhk5q4xn6OnRJU9nSzAK nm0Q== X-Gm-Message-State: AMke39mL6H5zvbLt3UjASqXlwoLbn46xjxpbs66oMuuChhlt5+uEUuGYDDJLcG80IjGLRPE6 X-Received: by 10.237.42.194 with SMTP id t60mr18290670qtd.269.1488824142983; Mon, 06 Mar 2017 10:15:42 -0800 (PST) From: Vladimir Olovyannikov To: edk2-devel@lists.01.org, jaben.carsey@intel.com, ruiyu.ni@intel.com Date: Mon, 6 Mar 2017 10:14:34 -0800 Message-Id: <1488824074-5202-1-git-send-email-vladimir.olovyannikov@broadcom.com> X-Mailer: git-send-email 1.9.1 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Vladimir Olovyannikov Subject: [edk2] [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: , Cc: Vladimir Olovyannikov MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If startup.nsh is placed into first location (embedded into the firmware im= age),=20 and the current directory has not been set (Internal Shell has just started= ),=20 Shell cannot execute startup because of the bug in the DoStartupScript:=20 after finding the correct path of the startup.nsh from the "First location"=20 and opening the file, and getting of the file handle, the correct path is=20 forgotten, and then RunScriptFile() receives just the name of the file=20 (from mStartupScript ariable).=20 It then attempts to check if this is a file with ShellIsFile() which fails=20 with "EFI_INVALID_PARAMETER" (current directory is NULL, so it cannot get=20 fully qualified file name), which causes Shell to exit and unload.=20 This patch fixes the issue. --- ShellPkg/Application/Shell/Shell.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shel= l/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 && ShellInf= oObject.ShellInitSettings.FileName !=3D NULL) { // @@ -1228,7 +1229,6 @@ DoStartupScript( // MapName =3D ShellInfoObject.NewEfiShellProtocol->GetMapFromDevicePath(&I= magePath); 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, mStartupSc= ript, 0); Status =3D ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileS= tringPath, &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_M= ODE_READ, 0); - FreePool(NewPath); + if (!EFI_ERROR (Status)) { + FileStringPath =3D gEfiShellProtocol->GetFilePathFromDevicePath(NewP= ath); + 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"", ShellInfoOb= ject.NewShellParametersProtocol); - ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle); + Status =3D RunScriptFile (FileStringPath, FileHandle, L"", ShellInfoOb= ject.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); } --=20 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel