summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2022-12-20 12:50:38 -0500
committerTom Rini <[email protected]>2022-12-20 12:50:48 -0500
commit1154e965d0bd16cf438afdaa4118e1455fd71a44 (patch)
tree9d862e44a520ea50e1cb8b15fd1ffd5675c5a018 /lib
parent566bc672a7474f4bf67b29514121ed41db21ed71 (diff)
parentad50ca5019ae2b4f6ad5ffb4d62808b640f7b8aa (diff)
Merge tag 'efi-2023-01-rc5' of https://source.denx.de/u-boot/custodians/u-boot-efi
Pull request for efi-2023-01-rc5 UEFI: * Improve parameter checking in efi_get_next_variable_name_mem() * Fix a bugs in management of security database via the eficonfig command Other: * Allow sound command to play multiple sounds
Diffstat (limited to 'lib')
-rw-r--r--lib/efi_loader/efi_helper.c34
-rw-r--r--lib/efi_loader/efi_var_mem.c6
-rw-r--r--lib/efi_selftest/efi_selftest_variables.c35
3 files changed, 72 insertions, 3 deletions
diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c
index 788cb9faec5..1f4ab2b419a 100644
--- a/lib/efi_loader/efi_helper.c
+++ b/lib/efi_loader/efi_helper.c
@@ -223,3 +223,37 @@ bool efi_varname_is_load_option(u16 *var_name16, int *index)
return false;
}
+
+/**
+ * efi_next_variable_name() - get next variable name
+ *
+ * This function is a wrapper of efi_get_next_variable_name_int().
+ * If efi_get_next_variable_name_int() returns EFI_BUFFER_TOO_SMALL,
+ * @size and @buf are updated by new buffer size and realloced buffer.
+ *
+ * @size: pointer to the buffer size
+ * @buf: pointer to the buffer
+ * @guid: pointer to the guid
+ * Return: status code
+ */
+efi_status_t efi_next_variable_name(efi_uintn_t *size, u16 **buf, efi_guid_t *guid)
+{
+ u16 *p;
+ efi_status_t ret;
+ efi_uintn_t buf_size = *size;
+
+ ret = efi_get_next_variable_name_int(&buf_size, *buf, guid);
+ if (ret == EFI_NOT_FOUND)
+ return ret;
+ if (ret == EFI_BUFFER_TOO_SMALL) {
+ p = realloc(*buf, buf_size);
+ if (!p)
+ return EFI_OUT_OF_RESOURCES;
+
+ *buf = p;
+ *size = buf_size;
+ ret = efi_get_next_variable_name_int(&buf_size, *buf, guid);
+ }
+
+ return ret;
+}
diff --git a/lib/efi_loader/efi_var_mem.c b/lib/efi_loader/efi_var_mem.c
index 13909b1d263..0bac594e004 100644
--- a/lib/efi_loader/efi_var_mem.c
+++ b/lib/efi_loader/efi_var_mem.c
@@ -315,14 +315,14 @@ efi_get_next_variable_name_mem(efi_uintn_t *variable_name_size,
u16 *variable_name, efi_guid_t *vendor)
{
struct efi_var_entry *var;
- efi_uintn_t old_size;
+ efi_uintn_t len, old_size;
u16 *pdata;
if (!variable_name_size || !variable_name || !vendor)
return EFI_INVALID_PARAMETER;
- if (u16_strnlen(variable_name, *variable_name_size) ==
- *variable_name_size)
+ len = *variable_name_size >> 1;
+ if (u16_strnlen(variable_name, len) == len)
return EFI_INVALID_PARAMETER;
if (!efi_var_mem_find(vendor, variable_name, &var) && *variable_name)
diff --git a/lib/efi_selftest/efi_selftest_variables.c b/lib/efi_selftest/efi_selftest_variables.c
index dc1d5c8f43e..c7a3fdbaa67 100644
--- a/lib/efi_selftest/efi_selftest_variables.c
+++ b/lib/efi_selftest/efi_selftest_variables.c
@@ -141,6 +141,41 @@ static int execute(void)
return EFI_ST_FAILURE;
}
/* Enumerate variables */
+
+ ret = runtime->get_next_variable_name(NULL, u"efi_st_var1", &guid);
+ if (ret != EFI_INVALID_PARAMETER) {
+ efi_st_error("GetNextVariableName missing parameter check\n");
+ return EFI_ST_FAILURE;
+ }
+
+ len = 24;
+ ret = runtime->get_next_variable_name(&len, NULL, &guid);
+ if (ret != EFI_INVALID_PARAMETER) {
+ efi_st_error("GetNextVariableName missing parameter check\n");
+ return EFI_ST_FAILURE;
+ }
+
+ len = 24;
+ ret = runtime->get_next_variable_name(&len, u"efi_st_var1", NULL);
+ if (ret != EFI_INVALID_PARAMETER) {
+ efi_st_error("GetNextVariableName missing parameter check\n");
+ return EFI_ST_FAILURE;
+ }
+
+ len = 1;
+ ret = runtime->get_next_variable_name(&len, u"", &guid);
+ if (ret != EFI_INVALID_PARAMETER) {
+ efi_st_error("GetNextVariableName missing parameter check\n");
+ return EFI_ST_FAILURE;
+ }
+
+ len = 16;
+ ret = runtime->get_next_variable_name(&len, u"efi_st_var1", &guid);
+ if (ret != EFI_INVALID_PARAMETER) {
+ efi_st_error("GetNextVariableName missing parameter check\n");
+ return EFI_ST_FAILURE;
+ }
+
boottime->set_mem(&guid, 16, 0);
*varname = 0;
flag = 0;