Skip to content

Commit

Permalink
fix efi_guid_t storage and comparison on windows and macos
Browse files Browse the repository at this point in the history
was causing "Couldn't find any EFI Boot Manager variables" erroneously.

Might be the cause of #80
  • Loading branch information
Neverous committed Aug 21, 2024
1 parent 7df7f26 commit f5cfe62
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/efivar-lite/efivar-lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
typedef struct ATTR_ALIGN(1)
{
#if defined(_WIN32)
TCHAR data[40];
TCHAR data[39];
#elif defined(__APPLE__)
char data[40];
char data[37];
#else
uint32_t a;
uint16_t b;
Expand Down
2 changes: 1 addition & 1 deletion src/efivar-lite.darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ int efi_get_next_variable_name(efi_guid_t **guid, char **name)

int efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b)
{
return memcmp(a, b, sizeof(efi_guid_t));
return strncmp(a->data, b->data, sizeof(a->data) / sizeof(a->data[0]));
}

int efi_error_get(unsigned int n, char **const filename, char **const function, int *line, char **const message, int *error)
Expand Down
6 changes: 3 additions & 3 deletions src/efivar-lite.win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void efi_set_get_next_variable_name_progress_cb(void (*progress_cb)(size_t, size
static ULONG current_offset = 0u;
static PVOID variables = nullptr;
static ULONG variables_size = 0u;
static efi_guid_t current_guid;
static efi_guid_t current_guid = {0};

int efi_get_next_variable_name(efi_guid_t **guid, TCHAR **name)
{
Expand Down Expand Up @@ -177,7 +177,7 @@ int efi_get_next_variable_name(efi_guid_t **guid, TCHAR **name)
else
current_offset += variable->NextEntryOffset;

if(_sntprintf_s(current_guid.data, 40, 39, _T("{%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}"),
if(_sntprintf_s(current_guid.data, 39, 39, _T("{%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}"),
variable->VendorGUID.Data1, variable->VendorGUID.Data2, variable->VendorGUID.Data3,
variable->VendorGUID.Data4[0], variable->VendorGUID.Data4[1], variable->VendorGUID.Data4[2], variable->VendorGUID.Data4[3],
variable->VendorGUID.Data4[4], variable->VendorGUID.Data4[5], variable->VendorGUID.Data4[6], variable->VendorGUID.Data4[7])
Expand All @@ -191,7 +191,7 @@ int efi_get_next_variable_name(efi_guid_t **guid, TCHAR **name)

int efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b)
{
return memcmp(a, b, sizeof(efi_guid_t));
return _tcsncmp(a->data, b->data, sizeof(a->data) / sizeof(a->data[0]));
}

static TCHAR error_buffer[1024];
Expand Down

0 comments on commit f5cfe62

Please sign in to comment.