blob: 3990d82c55002b7133cb8bbd7a05b0105483a1f6 [file] [log] [blame]
Brad Bishopbec4ebc2022-08-03 09:55:16 -04001From dc3f134436ad6852f1bad9542232e84166843a7e Mon Sep 17 00:00:00 2001
2From: Gowtham Suresh Kumar <gowtham.sureshkumar@arm.com>
3Date: Mon, 20 Dec 2021 20:01:10 +0000
4Subject: [PATCH] Add invalid parameter check in getNextVariableName()
5
6This patch resolves the failing tests in SCT related to
7getNextVariableName() function. The existing implementation is
8missing few cases where error codes are returned when called
9with certain paramters. These conditions are implemented in
10this patch based on the explanation provided in uefi spec.
11
12Upstream-Status: Pending [Not submitted to upstream yet]
13Signed-off-by: Gowtham Suresh Kumar <gowtham.sureshkumar@arm.com>
14
15
16---
17 .../smm_variable/backend/uefi_variable_store.c | 18 +++++++++++++++++-
18 1 file changed, 17 insertions(+), 1 deletion(-)
19
20diff --git a/components/service/smm_variable/backend/uefi_variable_store.c b/components/service/smm_variable/backend/uefi_variable_store.c
21index a1671074..a57b3346 100644
22--- a/components/service/smm_variable/backend/uefi_variable_store.c
23+++ b/components/service/smm_variable/backend/uefi_variable_store.c
24@@ -161,7 +161,7 @@ efi_status_t uefi_variable_store_set_variable(
25 bool should_sync_index = false;
26
27 if (status != EFI_SUCCESS) return status;
28-
29+
30 /*
31 * Runtime access to a data variable implies boot service access. Attributes that have
32 * EFI_VARIABLE_RUNTIME_ACCESS set must also have EFI_VARIABLE_BOOTSERVICE_ACCESS set.
33@@ -310,6 +310,22 @@ efi_status_t uefi_variable_store_get_next_variable_name(
34 status = EFI_NOT_FOUND;
35 *total_length = 0;
36
37+ /*
38+ * If input values of VariableName and VendorGuid are not a name and GUID of an
39+ * existing variable, EFI_INVALID_PARAMETER is returned.
40+ */
41+ if (cur->NameSize >= sizeof(int16_t)) {
42+ /*
43+ * Name must be at least one character long to accommodate
44+ * the mandatory null terminator.
45+ */
46+ if (cur->Name[0] != 0) {
47+ const struct variable_info *var_info = variable_index_find(&context->variable_index,&cur->Guid,cur->NameSize,cur->Name);
48+ if(var_info == NULL)
49+ return EFI_INVALID_PARAMETER;
50+ }
51+ }
52+
53 const struct variable_info *info = variable_index_find_next(
54 &context->variable_index,
55 &cur->Guid,