From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (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 F34CF210D7F46 for ; Fri, 3 Aug 2018 05:15:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 669D072636; Fri, 3 Aug 2018 12:15:41 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-198.rdu2.redhat.com [10.10.120.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5918F7C38; Fri, 3 Aug 2018 12:15:39 +0000 (UTC) From: Laszlo Ersek To: edk2-devel-01 Cc: Chao Zhang , Eric Dong , Jaben Carsey , Jiaxin Wu , Jiewen Yao , Liming Gao , Michael D Kinney , Roman Bacik , Ruiyu Ni , Siyuan Fu , Star Zeng Date: Fri, 3 Aug 2018 14:15:30 +0200 Message-Id: <20180803121537.32123-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 03 Aug 2018 12:15:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 03 Aug 2018 12:15:41 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [PATCH v2 0/7] UefiLib: centralize OpenFileByDevicePath() and fix its bugs X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Aug 2018 12:15:43 -0000 Repo: https://github.com/lersek/edk2.git Branch: open_file_by_devpath_tiano_1008_v2 This is version 2 of the patch set that was originally posted at: https://lists.01.org/pipermail/edk2-devel/2018-July/027253.html for . Changes are noted on every patch. The cumulative code difference is very small (not counting the FrameworkUefiLib copy of the function), so I'm including it here for easier review: > diff --git a/MdePkg/Include/Library/UefiLib.h b/MdePkg/Include/Library/UefiLib.h > index 2468bf2aee80..f950f1c9c648 100644 > --- a/MdePkg/Include/Library/UefiLib.h > +++ b/MdePkg/Include/Library/UefiLib.h > @@ -1554,9 +1554,11 @@ EfiLocateProtocolBuffer ( > traversal is stopped with an error, and a NULL EFI_FILE_PROTOCOL is output. > > @param[in,out] FilePath On input, the device path to the file or directory > - to open or create. On output, FilePath points one > - past the last node in the original device path that > - has been successfully processed. FilePath is set on > + to open or create. The caller is responsible for > + ensuring that the device path pointed-to by FilePath > + is well-formed. On output, FilePath points one past > + the last node in the original device path that has > + been successfully processed. FilePath is set on > output even if EfiOpenFileByDevicePath() returns an > error. > > diff --git a/MdePkg/Library/UefiLib/UefiLib.c b/MdePkg/Library/UefiLib/UefiLib.c > index d3e290178cd9..7bcac5613768 100644 > --- a/MdePkg/Library/UefiLib/UefiLib.c > +++ b/MdePkg/Library/UefiLib/UefiLib.c > @@ -1751,9 +1751,11 @@ EfiLocateProtocolBuffer ( > traversal is stopped with an error, and a NULL EFI_FILE_PROTOCOL is output. > > @param[in,out] FilePath On input, the device path to the file or directory > - to open or create. On output, FilePath points one > - past the last node in the original device path that > - has been successfully processed. FilePath is set on > + to open or create. The caller is responsible for > + ensuring that the device path pointed-to by FilePath > + is well-formed. On output, FilePath points one past > + the last node in the original device path that has > + been successfully processed. FilePath is set on > output even if EfiOpenFileByDevicePath() returns an > error. > > @@ -1808,6 +1810,10 @@ EfiOpenFileByDevicePath ( > EFI_HANDLE FileSystemHandle; > EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem; > EFI_FILE_PROTOCOL *LastFile; > + FILEPATH_DEVICE_PATH *FilePathNode; > + CHAR16 *AlignedPathName; > + CHAR16 *PathName; > + EFI_FILE_PROTOCOL *NextFile; > > if (File == NULL) { > return EFI_INVALID_PARAMETER; > @@ -1854,15 +1860,6 @@ EfiOpenFileByDevicePath ( > // Traverse the device path nodes relative to the filesystem. > // > while (!IsDevicePathEnd (*FilePath)) { > - // > - // Keep local variables that relate to the current device path node tightly > - // scoped. > - // > - FILEPATH_DEVICE_PATH *FilePathNode; > - CHAR16 *AlignedPathName; > - CHAR16 *PathName; > - EFI_FILE_PROTOCOL *NextFile; > - > if (DevicePathType (*FilePath) != MEDIA_DEVICE_PATH || > DevicePathSubType (*FilePath) != MEDIA_FILEPATH_DP) { > Status = EFI_INVALID_PARAMETER; > @@ -1942,6 +1939,10 @@ EfiOpenFileByDevicePath ( > CloseLastFile: > LastFile->Close (LastFile); > > + // > + // We are on the error path; we must have set an error Status for returning > + // to the caller. > + // > ASSERT (EFI_ERROR (Status)); > return Status; > } > diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c > index 312a92d7461a..aef85c470143 100644 > --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c > +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c > @@ -163,7 +163,7 @@ UpdatePage( > > gSecureBootPrivateData->FileContext->FileName = FileName; > > - EfiOpenFileByDevicePath( > + EfiOpenFileByDevicePath ( > &FilePath, > &gSecureBootPrivateData->FileContext->FHandle, > EFI_FILE_MODE_READ, Cc: Chao Zhang Cc: Eric Dong Cc: Jaben Carsey Cc: Jiaxin Wu Cc: Jiewen Yao Cc: Liming Gao Cc: Michael D Kinney Cc: Roman Bacik Cc: Ruiyu Ni Cc: Siyuan Fu Cc: Star Zeng Thanks, Laszlo Laszlo Ersek (7): MdePkg/UefiLib: introduce EfiOpenFileByDevicePath() IntelFrameworkPkg/FrameworkUefiLib: introduce EfiOpenFileByDevicePath() MdeModulePkg/RamDiskDxe: replace OpenFileByDevicePath() with UefiLib API NetworkPkg/TlsAuthConfigDxe: replace OpenFileByDevicePath() with UefiLib API SecurityPkg/SecureBootConfigDxe: replace OpenFileByDevicePath() with UefiLib API ShellPkg/UefiShellLib: drop DeviceHandle param of ShellOpenFileByDevicePath() ShellPkg/UefiShellLib: rebase ShellOpenFileByDevicePath() to UefiLib API IntelFrameworkPkg/Library/FrameworkUefiLib/FrameworkUefiLib.inf | 1 + IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c | 227 ++++++++++++++++++++ MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf | 1 - MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskFileExplorer.c | 140 ------------ MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c | 2 +- MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h | 39 ---- MdePkg/Include/Library/UefiLib.h | 88 ++++++++ MdePkg/Library/UefiLib/UefiLib.c | 227 ++++++++++++++++++++ MdePkg/Library/UefiLib/UefiLib.inf | 1 + NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigDxe.inf | 1 - NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c | 141 +----------- SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf | 1 - SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c | 151 +------------ ShellPkg/Include/Library/ShellLib.h | 2 - ShellPkg/Library/UefiShellLib/UefiShellLib.c | 118 +--------- ShellPkg/Library/UefiShellLib/UefiShellLib.inf | 3 +- 16 files changed, 552 insertions(+), 591 deletions(-) -- 2.14.1.3.gb7cf6e02401b