efi: Fix potential issues with LocateHandle invocations

This commit is contained in:
mintsuki 2022-07-01 08:03:21 +02:00
parent 098e8679f3
commit f9e90da2c2
2 changed files with 21 additions and 8 deletions

View File

@ -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_GUID block_io_guid = BLOCK_IO_PROTOCOL;
EFI_HANDLE *handles = NULL;
UINTN handles_size = 0;
EFI_HANDLE tmp_handles[1];
gBS->LocateHandle(ByProtocol, &block_io_guid, NULL, &handles_size, handles);
EFI_GUID block_io_guid = BLOCK_IO_PROTOCOL;
EFI_HANDLE *handles = tmp_handles;
UINTN handles_size = 1;
status = 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);

View File

@ -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);