From abfd7b16aa002316a18e9b1d871f869158e78fc0 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Fri, 6 Sep 2013 11:02:13 -0400 Subject: [PATCH] Do better error checking in read_boot_u16(), and simplify it. Why am I even doing this stupid bitshifting? Signed-off-by: Peter Jones --- src/efibootmgr/efibootmgr.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c index a774ee2..3581069 100644 --- a/src/efibootmgr/efibootmgr.c +++ b/src/efibootmgr/efibootmgr.c @@ -361,16 +361,21 @@ static int read_boot_u16(const char *name) { efi_guid_t guid = EFI_GLOBAL_GUID; - uint8_t *data = NULL; + uint16_t *data = NULL; size_t data_size = 0; uint32_t attributes = 0; int rc; - rc = efi_get_variable(guid, name, &data, &data_size, &attributes); + rc = efi_get_variable(guid, name, (uint8_t **)&data, &data_size, + &attributes); if (rc < 0) return rc; + if (data_size != 2) { + errno = EINVAL; + return -1; + } - rc = (data[0] & 0xff) | ((data[1] & 0xff) << 8); + rc = data[0]; return rc; } -- 2.11.0