From d89b722ef7059b81a480419ba7b81f1143f085e5 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 24 Jul 2017 14:02:37 -0400 Subject: [PATCH] Exit our dir->Read() loop if it says there's 0 bytes of data to read. When dir->Read() says bs=0, we shouldn't try to allocate a buffer and read into it. On edk2 this works because there's an implicit (possibly accidental) minimum size of one pool list entry that can be allocated, so you wind up getting (I think) 8 bytes. When Rob Clark tried to run this under uboot's emulated UEFI environment, dir->Read() returned 0 and when we passed that to AllocateZeroPool() less good things happened. So just check for that case and exit appropriately. Signed-off-by: Peter Jones --- fallback.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fallback.c b/fallback.c index 5e4a396..81f5303 100644 --- a/fallback.c +++ b/fallback.c @@ -591,6 +591,10 @@ find_boot_csv(EFI_FILE_HANDLE fh, CHAR16 *dirname) FreePool(buffer); return rc; } + /* If there's no data to read, don't try to allocate 0 bytes + * and read the data... */ + if (bs == 0) + break; buffer = AllocateZeroPool(bs); if (!buffer) {