boot: port more code over to get_file_info_harder()

This commit is contained in:
Lennart Poettering
2021-09-21 15:29:03 +02:00
parent 19c896e99c
commit ef6ff81a53
3 changed files with 10 additions and 27 deletions

View File

@@ -1226,7 +1226,7 @@ static VOID config_entry_bump_counters(
_cleanup_(FileHandleClosep) EFI_FILE_HANDLE handle = NULL;
static const EFI_GUID EfiFileInfoGuid = EFI_FILE_INFO_ID;
_cleanup_freepool_ EFI_FILE_INFO *file_info = NULL;
UINTN file_info_size, a, b;
UINTN file_info_size;
EFI_STATUS r;
assert(entry);
@@ -1244,26 +1244,9 @@ static VOID config_entry_bump_counters(
if (EFI_ERROR(r))
return;
a = StrLen(entry->current_name);
b = StrLen(entry->next_name);
file_info_size = OFFSETOF(EFI_FILE_INFO, FileName) + (a > b ? a : b) + 1;
for (;;) {
file_info = AllocatePool(file_info_size);
r = uefi_call_wrapper(handle->GetInfo, 4, handle, (EFI_GUID*) &EfiFileInfoGuid, &file_info_size, file_info);
if (!EFI_ERROR(r))
break;
if (r != EFI_BUFFER_TOO_SMALL || file_info_size * 2 < file_info_size) {
log_error_stall(L"Failed to get file info for '%s': %r", old_path, r);
return;
}
file_info_size *= 2;
FreePool(file_info);
}
r = get_file_info_harder(handle, &file_info, &file_info_size);
if (EFI_ERROR(r))
return;
/* And rename the file */
StrCpy(file_info->FileName, entry->next_name);

View File

@@ -91,9 +91,9 @@ EFI_STATUS devicetree_install(struct devicetree_state *state,
if (EFI_ERROR(err))
return err;
info = LibFileInfo(handle);
if (!info)
return EFI_OUT_OF_RESOURCES;
err = get_file_info_harder(handle, &info, NULL);
if (EFI_ERROR(err))
return err;
if (info->FileSize < FDT_V1_SIZE || info->FileSize > 32 * 1024 * 1024)
/* 32MB device tree blob doesn't seem right */
return EFI_INVALID_PARAMETER;

View File

@@ -263,9 +263,9 @@ EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) {
return err;
}
info = LibFileInfo(handle);
if (!info)
return log_oom();
err = get_file_info_harder(handle, &info, NULL);
if (EFI_ERROR(err))
return log_error_status_stall(err, L"Failed to get file info for random seed: %r");
size = info->FileSize;
if (size < RANDOM_MAX_SIZE_MIN)