Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

efiboot: prevent overwriting variables with exactly the same value #220

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions include/efiboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -3593,6 +3593,16 @@
auto [value, attributes] = variable;
Raw_data bytes;
size_t size = serialize(bytes, value);
// Skip overwriting with exactly the same value
if(const auto current = EFIBoot::get_variable<Raw_data>(guid, name); current)
{
const auto &[current_bytes, current_attributes] = *current;
Fixed Show fixed Hide fixed
if(current_attributes == attributes && current_bytes == bytes)
return true;
}

// Don't care about the error from get_variable
efi_error_clear();
return efi_set_variable(guid, name.c_str(), bytes.data(), size, attributes, mode) == 0;
}

Expand All @@ -3602,6 +3612,16 @@
auto [value, attributes] = variable;
Raw_data bytes;
size_t size = serialize_list(bytes, value);
// Skip overwriting with exactly the same value
if(const auto current = EFIBoot::get_variable<Raw_data>(guid, name); current)
{
const auto &[current_bytes, current_attributes] = *current;
Fixed Show fixed Hide fixed
if(current_attributes == attributes && current_bytes == bytes)
return true;
}

// Don't care about the error from get_variable
efi_error_clear();
return efi_set_variable(guid, name.c_str(), bytes.data(), size, attributes, mode) == 0;
}

Expand Down
1 change: 1 addition & 0 deletions include/efivar-lite/efivar-lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ void efi_set_get_next_variable_name_progress_cb(void (*progress_cb)(size_t, size
int efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b);

int efi_error_get(unsigned int n, TCHAR **const filename, TCHAR **const function, int *line, TCHAR **const message, int *error) ATTR_NONNULL(2, 3, 4, 5, 6);
void efi_error_clear(void);
5 changes: 5 additions & 0 deletions src/efivar-lite.darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,8 @@ int efi_error_get(unsigned int n, char **const filename, char **const function,
*message = mach_error_string(err);
return 1;
}

void efi_error_clear(void)
{
// Nothing to do
}
5 changes: 5 additions & 0 deletions src/efivar-lite.win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,8 @@ int efi_error_get(unsigned int n, TCHAR **const filename, TCHAR **const function
*message = error_buffer;
return 1;
}

void efi_error_clear(void)
{
// Nothing to do
}
Loading