diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 3ed08e7c377e7f25b111414ca4e59c3d8b7a1fc6..0c92cc1807cba5ea09fdfecc9227f7948a50c339 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1364,28 +1364,28 @@ static efi_status_t efi_locate_handle( return EFI_INVALID_PARAMETER; } - /* - * efi_locate_handle_buffer uses this function for - * the calculation of the necessary buffer size. - * So do not require a buffer for buffersize == 0. - */ - if (!buffer_size || (*buffer_size && !buffer)) - return EFI_INVALID_PARAMETER; - /* Count how much space we need */ list_for_each_entry(efiobj, &efi_obj_list, link) { if (!efi_search(search_type, protocol, search_key, efiobj)) size += sizeof(void *); } + if (size == 0) + return EFI_NOT_FOUND; + + if (!buffer_size) + return EFI_INVALID_PARAMETER; + if (*buffer_size < size) { *buffer_size = size; return EFI_BUFFER_TOO_SMALL; } *buffer_size = size; - if (size == 0) - return EFI_NOT_FOUND; + + /* The buffer size is sufficient but there is not buffer */ + if (!buffer) + return EFI_INVALID_PARAMETER; /* Then fill the array */ list_for_each_entry(efiobj, &efi_obj_list, link) {