From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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) 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) 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) From: Vladimir Olovyannikov To: edk2-devel@lists.01.org, jaben.carsey@intel.com, ruiyu.ni@intel.com Cc: Vladimir Olovyannikov 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: [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:15:44 -0000 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 started), Shell cannot execute startup because of the bug in the DoStartupScript: after finding the correct path of the startup.nsh from the "First location" 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 fails 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(-) 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 = CHAR_NULL; Key.ScanCode = 0; FileHandle = NULL; + FileStringPath = NULL; if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup && ShellInfoObject.ShellInitSettings.FileName != NULL) { // @@ -1228,7 +1229,6 @@ DoStartupScript( // MapName = ShellInfoObject.NewEfiShellProtocol->GetMapFromDevicePath(&ImagePath); if (MapName != NULL) { - FileStringPath = NULL; NewSize = 0; FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, MapName, 0); if (FileStringPath == NULL) { @@ -1242,10 +1242,10 @@ DoStartupScript( PathRemoveLastItem(FileStringPath); FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, mStartupScript, 0); Status = ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ); - FreePool(FileStringPath); } } if (EFI_ERROR(Status)) { + SHELL_FREE_NON_NULL (FileStringPath); NamePath = FileDevicePath (NULL, mStartupScript); NewPath = AppendDevicePathNode (ImagePath, NamePath); FreePool(NamePath); @@ -1254,15 +1254,21 @@ DoStartupScript( // Try the location // Status = InternalOpenFileDevicePath(NewPath, &FileHandle, EFI_FILE_MODE_READ, 0); - FreePool(NewPath); + if (!EFI_ERROR (Status)) { + FileStringPath = gEfiShellProtocol->GetFilePathFromDevicePath(NewPath); + if (FileStringPath == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } + } + FreePool (NewPath); } // // If we got a file, run it // if (!EFI_ERROR(Status) && FileHandle != NULL) { - Status = RunScriptFile (mStartupScript, FileHandle, L"", ShellInfoObject.NewShellParametersProtocol); - ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle); + Status = RunScriptFile (FileStringPath, FileHandle, L"", ShellInfoObject.NewShellParametersProtocol); } else { + SHELL_FREE_NON_NULL (FileStringPath); FileStringPath = ShellFindFilePath(mStartupScript); if (FileStringPath == NULL) { // @@ -1272,10 +1278,13 @@ DoStartupScript( ASSERT(FileHandle == NULL); } else { Status = RunScriptFile(FileStringPath, NULL, L"", ShellInfoObject.NewShellParametersProtocol); - FreePool(FileStringPath); } } + SHELL_FREE_NON_NULL (FileStringPath); + if (FileHandle != NULL) { + ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle); + } return (Status); } -- 1.9.1