Fixes bug triggered by ShellPkg code, in usage of EFI_FILE_PROTOCOL's Open().
Cc: Leif Lindholm <l...@nuviainc.com> Cc: Michael D Kinney <michael.d.kin...@intel.com> Cc: Bret Barkelew <bret.barke...@microsoft.com> Signed-off-by: Pedro Falcato <pedro.falc...@gmail.com> --- Features/Ext4Pkg/Ext4Dxe/File.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/File.c b/Features/Ext4Pkg/Ext4Dxe/File.c index 0f5fa6f73fb6..a3eff2b48a07 100644 --- a/Features/Ext4Pkg/Ext4Dxe/File.c +++ b/Features/Ext4Pkg/Ext4Dxe/File.c @@ -207,6 +207,11 @@ Ext4Open ( FileName += Length; + if (StrCmp(PathSegment, L".") == 0) { + // Opens of "." are a no-op + continue; + } + DEBUG ((DEBUG_FS, "[ext4] Opening %s\n", PathSegment)); if (!Ext4FileIsDir (Current)) { @@ -512,12 +517,20 @@ Ext4GetFileInfo ( IN EXT4_FILE *File, OUT EFI_FILE_INFO *Info, IN OUT UINTN *BufferSize ) { - UINTN FileNameLen; - UINTN FileNameSize; - UINTN NeededLength; + UINTN FileNameLen; + UINTN FileNameSize; + UINTN NeededLength; + CONST CHAR16 *FileName; - FileNameLen = StrLen (File->FileName); - FileNameSize = StrSize (File->FileName); + if (File->InodeNum == 2) { + // Root inode gets a filename of "", regardless of how it was opened. + FileName = L""; + } else { + FileName = File->FileName; + } + + FileNameLen = StrLen (FileName); + FileNameSize = StrSize (FileName); NeededLength = SIZE_OF_EFI_FILE_INFO + FileNameSize; @@ -540,7 +553,7 @@ Ext4GetFileInfo ( *BufferSize = NeededLength; - return StrCpyS (Info->FileName, FileNameLen + 1, File->FileName); + return StrCpyS (Info->FileName, FileNameLen + 1, FileName); } /** @@ -687,6 +700,7 @@ Ext4DuplicateFile ( { EXT4_PARTITION *Partition; EXT4_FILE *File; + EFI_STATUS Status; Partition = Original->Partition; File = AllocateZeroPool (sizeof (EXT4_FILE)); @@ -717,7 +731,8 @@ Ext4DuplicateFile ( File->InodeNum = Original->InodeNum; File->OpenMode = 0; // Will be filled by other code - if (!Ext4InitExtentsMap (File)) { + Status = Ext4InitExtentsMap (File); + if (EFI_ERROR (Status)) { FreePool (File->FileName); FreePool (File->Inode); FreePool (File); -- 2.33.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#79662): https://edk2.groups.io/g/devel/message/79662 Mute This Topic: https://groups.io/mt/85043011/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-