:: commit 6f18e7545ef97726fe86ac0aea5294ff0cda139d

mintsuki <mintsuki@protonmail.com> — 2022-07-01 06:03

parents: b3af3b998a

efi: Fix potential issues with LocateHandle invocations

diff --git a/common/drivers/disk.s2.c b/common/drivers/disk.s2.c
index b07a2b4c..6e4d457a 100644
--- a/common/drivers/disk.s2.c
+++ b/common/drivers/disk.s2.c
@@ -389,15 +389,26 @@ static void find_part_handles(EFI_HANDLE *handles, size_t handle_count) {
 void disk_create_index(void) {
     EFI_STATUS status;
 
+    EFI_HANDLE tmp_handles[1];
+
     EFI_GUID block_io_guid = BLOCK_IO_PROTOCOL;
-    EFI_HANDLE *handles = NULL;
-    UINTN handles_size = 0;
+    EFI_HANDLE *handles = tmp_handles;
+    UINTN handles_size = 1;
+
+    status = gBS->LocateHandle(ByProtocol, &block_io_guid, NULL, &handles_size, handles);
 
-    gBS->LocateHandle(ByProtocol, &block_io_guid, NULL, &handles_size, handles);
+    if (status != EFI_BUFFER_TOO_SMALL && status != EFI_SUCCESS) {
+        goto fail;
+    }
 
     handles = ext_mem_alloc(handles_size);
 
-    gBS->LocateHandle(ByProtocol, &block_io_guid, NULL, &handles_size, handles);
+    status = gBS->LocateHandle(ByProtocol, &block_io_guid, NULL, &handles_size, handles);
+
+    if (status != EFI_SUCCESS) {
+fail:
+        panic(false, "LocateHandle for BLOCK_IO_PROTOCOL failed. Machine not supported by Limine UEFI.");
+    }
 
     volume_index = ext_mem_alloc(sizeof(struct volume) * MAX_VOLUMES);
 
diff --git a/common/drivers/edid.c b/common/drivers/edid.c
index 2b098a39..1de88f2e 100644
--- a/common/drivers/edid.c
+++ b/common/drivers/edid.c
@@ -54,13 +54,15 @@ struct edid_info_struct *get_edid_info(void) {
 
     EFI_STATUS status;
 
-    EFI_HANDLE *handles = NULL;
-    UINTN handles_size = 0;
+    EFI_HANDLE tmp_handles[1];
+
+    EFI_HANDLE *handles = tmp_handles;
+    UINTN handles_size = 1;
     EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
 
     status = gBS->LocateHandle(ByProtocol, &gop_guid, NULL, &handles_size, handles);
 
-    if (status && status != EFI_BUFFER_TOO_SMALL)
+    if (status != EFI_SUCCESS && status != EFI_BUFFER_TOO_SMALL)
         goto fail_n;
 
     handles = ext_mem_alloc(handles_size);
tab: 248 wrap: offon