From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org 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 B2E93220D4BEB for ; Mon, 13 Nov 2017 23:49:30 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Nov 2017 23:53:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,393,1505804400"; d="scan'208";a="1243809165" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.13]) by fmsmga002.fm.intel.com with ESMTP; 13 Nov 2017 23:53:36 -0800 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Jaben Carsey , Ruiyu Ni Date: Tue, 14 Nov 2017 15:53:33 +0800 Message-Id: <20171114075333.12024-1-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 Subject: [PATCH] ShellPkg/Shell: Check the OpenVolume result in OpenRootByHandle() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Nov 2017 07:49:30 -0000 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=779 For the API EfiShellOpenRootByHandle(): The return status of the call to SimpleFileSystem->OpenVolume should be checked. It is possible that there is a media change in the device (like CD/DVD ROM). In such case, the volume root opened and/or the device path opened previously (also within EfiShellOpenRootByHandle) may be invalid. This commit adds a check for the result of OpenVolume before subsequently calling functions like EfiShellGetMapFromDevicePath() & ConvertEfiFileProtocolToShellHandle(). Cc: Jaben Carsey Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu --- ShellPkg/Application/Shell/ShellProtocol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c index 5e34b8dad1..0dee267353 100644 --- a/ShellPkg/Application/Shell/ShellProtocol.c +++ b/ShellPkg/Application/Shell/ShellProtocol.c @@ -827,7 +827,8 @@ EfiShellGetDeviceName( @retval EFI_NOT_FOUND EFI_SIMPLE_FILE_SYSTEM could not be found or the root directory could not be opened. @retval EFI_VOLUME_CORRUPTED The data structures in the volume were corrupted. - @retval EFI_DEVICE_ERROR The device had an error + @retval EFI_DEVICE_ERROR The device had an error. + @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no longer supported. **/ EFI_STATUS EFIAPI @@ -867,8 +868,12 @@ EfiShellOpenRootByHandle( // Open the root volume now... // Status = SimpleFileSystem->OpenVolume(SimpleFileSystem, &RealFileHandle); + if (EFI_ERROR(Status)) { + return Status; + } + *FileHandle = ConvertEfiFileProtocolToShellHandle(RealFileHandle, EfiShellGetMapFromDevicePath(&DevPath)); - return (Status); + return (EFI_SUCCESS); } /** -- 2.12.0.windows.1