[PATCH 2/6] efi_loader: Introduce helper functions for EFI
Ilias Apalodimas
ilias.apalodimas at linaro.org
Mon Dec 28 23:06:50 CET 2020
Hi Heinrich,
> > +
> > + /* make sure we have enough space for replacements */
> > + if (u16_strsize(name) < sizeof(*name) * start + u16_strsize(L"####")) {
> > + ret = EFI_INVALID_PARAMETER;
> > + goto out;
> > + }
> > + boot_order_size = sizeof(boot_order);
> > + ret = efi_get_variable_int(L"BootCurrent",
> > + &efi_global_variable_guid, NULL,
> > + &boot_order_size, &boot_order, NULL);
> > + if (ret != EFI_SUCCESS)
> > + goto out;
> > +
> > + name_dup = u16_strdup(name);
> > + if (!name_dup) {
> > + ret = EFI_OUT_OF_RESOURCES;
> > + goto out;
> > + }
> > + /* Match name variable to BootCurrent */
> > + name_dup[start] = hexmap[(boot_order & 0xf000) >> 12];
> > + name_dup[start + 1] = hexmap[(boot_order & 0x0f00) >> 8];
> > + name_dup[start + 2] = hexmap[(boot_order & 0x00f0) >> 4];
> > + name_dup[start + 3] = hexmap[(boot_order & 0x000f) >> 0];
>
> Please, consider using efi_create_indexed_name().
That one doesn't check any input variables and just asks for the user to
provide sufficient buffers for the output.
I am explicitly checking the sizes here. I guess I can add similar checks to
efi_create_indexed_name() and use it, instead of open coding again.
Just a note here, there's similar code to the efi bootmgr, so we should
probably start replacing all of the functions.
Regards
/Ilias
>
> Best regards
>
> Heinrich
>
> > +
> > + var_value = get_var(name_dup, &efi_global_variable_guid, &size);
> > + if (!var_value) {
> > + ret = EFI_NOT_FOUND;
> > + goto out;
> > + }
> > +
> > + ret = string_to_load_args(var_value, info);
> > + if (ret != EFI_SUCCESS)
> > + goto out;
> > +
> > + if (fs_set_blk_dev(info->dev, info->part, FS_TYPE_ANY)) {
> > + ret = EFI_NO_MEDIA;
> > + goto out;
> > + }
> > +
> > + if (!fs_exists(info->filename)) {
> > + ret = EFI_NOT_FOUND;
> > + goto out;
> > + }
> > +
> > +out:
> > + free(var_value);
> > + free(name_dup);
> > + return ret;
> > +}
> >
>
More information about the U-Boot
mailing list