Skip to content

Commit

Permalink
Fix specs EFI_FILE_PROTOCOL.Read() non-compliance for directory listing
Browse files Browse the repository at this point in the history
* Closes #4.
  • Loading branch information
pbatard committed Apr 11, 2023
1 parent 50324b7 commit 6982701
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions uefi-driver/uefi_file.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* uefi_file.c - SimpleFileIo Interface */
/*
* Copyright © 2014-2021 Pete Batard <pete@akeo.ie>
* Copyright © 2014-2023 Pete Batard <pete@akeo.ie>
* Based on iPXE's efi_driver.c and efi_file.c:
* Copyright © 2011,2013 Michael Brown <mbrown@fensystems.co.uk>.
*
Expand Down Expand Up @@ -306,6 +306,12 @@ static INT32 DirHook(VOID* Data, CONST CHAR16* Name,
FS_ASSERT(NameLen < 256);

if (HookData->Info->Size < ((UINT64)NameLen + 1) * sizeof(CHAR16)) {
/*
* Per specs: If the buffer is not large enough to hold the current directory
* entry, EFI_BUFFER_TOO_SMALL is returned and Len is set to the size of the
* buffer needed to read the entry.
*/
HookData->Info->Size = ((UINT64)NameLen + 1) * sizeof(CHAR16);
NtfsSetErrno(EFI_BUFFER_TOO_SMALL);
return -1;
}
Expand Down Expand Up @@ -342,16 +348,18 @@ FileReadDir(EFI_NTFS_FILE* File, UINTN* Len, VOID* Data)

HookData.Info->Size = *Len;
Status = NtfsReadDirectory(File, DirHook, &HookData);
*Len = (UINTN)HookData.Info->Size;

if (EFI_ERROR(Status)) {
if (Status == EFI_END_OF_FILE) {
*Len = 0;
return EFI_SUCCESS;
}
PrintStatusError(Status, L"Directory listing failed");
if (Status != EFI_BUFFER_TOO_SMALL)
PrintStatusError(Status, L"Directory listing failed");
return Status;
}

*Len = (UINTN)HookData.Info->Size;
return EFI_SUCCESS;
}

Expand Down

0 comments on commit 6982701

Please sign in to comment.