From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: u-boot@lists.denx.de
Subject: [PATCH 2/6] efi_loader: Introduce helper functions for EFI
Date: Tue, 29 Dec 2020 00:06:50 +0200 [thread overview]
Message-ID: <X+pW+mSfGfY+qpIT@enceladus> (raw)
In-Reply-To: <de5a707b-8b8b-2f78-09b5-227424726a1d@gmx.de>
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;
> > +}
> >
>
next prev parent reply other threads:[~2020-12-28 22:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-28 12:24 [PATCH 0/6] Change logic of EFI LoadFile2 protocol for initrd loading Ilias Apalodimas
2020-12-28 12:24 ` [PATCH 1/6] efi_loader: remove unconditional initialization of file2 protocol for initrd Ilias Apalodimas
2020-12-28 12:24 ` [PATCH 2/6] efi_loader: Introduce helper functions for EFI Ilias Apalodimas
2020-12-28 14:49 ` Heinrich Schuchardt
2020-12-28 22:06 ` Ilias Apalodimas [this message]
2020-12-28 12:24 ` [PATCH 3/6] efi_loader: Replace config option with EFI variable for initrd loading Ilias Apalodimas
2020-12-28 13:10 ` Ilias Apalodimas
2020-12-28 14:55 ` Heinrich Schuchardt
2020-12-28 22:03 ` Ilias Apalodimas
2020-12-28 12:24 ` [PATCH 4/6] efi_loader: Remove unused headers from efi_load_initrd.c Ilias Apalodimas
2020-12-28 15:06 ` Heinrich Schuchardt
2020-12-28 15:08 ` [PATCH] " Heinrich Schuchardt
2020-12-28 12:24 ` [PATCH 5/6] efi_selftest: Modify self-tests for initrd loading Ilias Apalodimas
2020-12-28 12:24 ` [PATCH 6/6] efi_loader: bootmgr: use get_var from efi_helper file Ilias Apalodimas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=X+pW+mSfGfY+qpIT@enceladus \
--to=ilias.apalodimas@linaro.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox