From c3b973a91e8166eef46fd0d11ea2c4b06ca79442 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Mon, 28 Jun 2021 12:18:08 +0100 Subject: [PATCH] trivial: Prevent critical warning when the EFI variable has no data I don't think this can happen in reality, but I hit it when mocking up an efivar directory using FWUPD_SYSFSFWDIR with a 4 byte file. --- libfwupdplugin/fu-efivar-linux.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libfwupdplugin/fu-efivar-linux.c b/libfwupdplugin/fu-efivar-linux.c index 509795beb..fbfc9a40a 100644 --- a/libfwupdplugin/fu-efivar-linux.c +++ b/libfwupdplugin/fu-efivar-linux.c @@ -250,6 +250,13 @@ fu_efivar_get_data_impl (const gchar *guid, const gchar *name, guint8 **data, /* read out the data */ data_sz_tmp = sz - sizeof(attr_tmp); + if (data_sz_tmp == 0) { + g_set_error_literal (error, + G_IO_ERROR, + G_IO_ERROR_INVALID_DATA, + "no data to read"); + return FALSE; + } if (data_sz != NULL) *data_sz = data_sz_tmp; if (data != NULL) {