Skip to content

Commit 121f88a

Browse files
committed
Return attributes in GetVariable() on buffer error
UEFI 2.8 and newer specifies that GetVariable() returns variable attributes even if the EFI_BUFFER_TOO_SMALL error is encountered. Return this value in v2 protocol. Note that in v2, in the EFI_BUFFER_TOO_SMALL case, `attributes` comes after `data_len` to be compatible with v1. Signed-off-by: Tu Dinh <[email protected]>
1 parent a94771b commit 121f88a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

handler.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,15 @@ internal_get_variable(const uint8_t *name, UINTN name_len, const EFI_GUID *guid,
277277
static void
278278
do_get_variable(uint8_t *comm_buf)
279279
{
280+
UINT32 version;
280281
uint8_t *ptr, *name;
281282
EFI_GUID guid;
282283
UINTN name_len, data_len;
283284
BOOLEAN at_runtime;
284285
struct efi_variable *l;
285286

286287
ptr = comm_buf;
287-
if (snoop_command(&ptr, NULL, NULL, NULL) != EFI_SUCCESS) {
288+
if (snoop_command(&ptr, &version, NULL, NULL) != EFI_SUCCESS) {
288289
assert(0);
289290
return;
290291
}
@@ -310,6 +311,8 @@ do_get_variable(uint8_t *comm_buf)
310311
if (data_len < l->data_len) {
311312
serialize_result(&ptr, EFI_BUFFER_TOO_SMALL);
312313
serialize_uintn(&ptr, l->data_len);
314+
if (version >= 2)
315+
serialize_uint32(&ptr, l->attributes);
313316
} else {
314317
serialize_result(&ptr, EFI_SUCCESS);
315318
serialize_uint32(&ptr, l->attributes);

test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ MULTI_TEST(test_get_variable_too_small)
903903
{
904904
uint8_t *ptr;
905905
UINTN data_len;
906+
UINT32 attr;
906907
EFI_STATUS status;
907908

908909
reset_test(version);
@@ -918,6 +919,11 @@ MULTI_TEST(test_get_variable_too_small)
918919
g_assert_cmpuint(status, ==, EFI_BUFFER_TOO_SMALL);
919920
data_len = unserialize_uintn(&ptr);
920921
g_assert_cmpuint(data_len, ==, sizeof(tdata1));
922+
923+
if (version >= 2) {
924+
attr = unserialize_uint32(&ptr);
925+
g_assert_cmpuint(attr, ==, ATTR_B);
926+
}
921927
}
922928

923929
MULTI_TEST(test_query_variable_info)

0 commit comments

Comments
 (0)