From b9e452423c25888e147e8aaa25ad8087176eb3a0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 8 Feb 2019 16:23:40 +0100 Subject: [PATCH] efi: beef up efivar_get_xyz() to accept NULL return values --- src/boot/efi/util.c | 11 ++++++++--- src/boot/efi/util.h | 7 +++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index f1f1674..bc1d4ae 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -117,6 +117,9 @@ EFI_STATUS efivar_get(const CHAR16 *name, CHAR16 **value) { if ((size % 2) != 0) return EFI_INVALID_PARAMETER; + if (!value) + return EFI_SUCCESS; + /* Return buffer directly if it happens to be NUL terminated already */ if (size >= 2 && buf[size-2] == 0 && buf[size-1] == 0) { *value = (CHAR16*) buf; @@ -141,7 +144,7 @@ EFI_STATUS efivar_get_int(const CHAR16 *name, UINTN *i) { EFI_STATUS err; err = efivar_get(name, &val); - if (!EFI_ERROR(err)) + if (!EFI_ERROR(err) && i) *i = Atoi(val); return err; @@ -159,8 +162,10 @@ EFI_STATUS efivar_get_raw(const EFI_GUID *vendor, const CHAR16 *name, CHAR8 **bu err = uefi_call_wrapper(RT->GetVariable, 5, (CHAR16*) name, (EFI_GUID *)vendor, NULL, &l, buf); if (!EFI_ERROR(err)) { - *buffer = buf; - buf = NULL; + + if (buffer) + *buffer = TAKE_PTR(buf); + if (size) *size = l; } diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index 4ba7050..8c5e35a 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -55,3 +55,10 @@ const EFI_GUID loader_guid; #define UINTN_MAX (~(UINTN)0) #define INTN_MAX ((INTN)(UINTN_MAX>>1)) + +#define TAKE_PTR(ptr) \ + ({ \ + typeof(ptr) _ptr_ = (ptr); \ + (ptr) = NULL; \ + _ptr_; \ + }) -- 2.7.4