Skip to content

Commit

Permalink
Change set&append data to be const.
Browse files Browse the repository at this point in the history
All implementations of set_variable and append_variable never modify
the data pointed to. Callers don't know by the function signitures that
their data will not be modified nor can they pass const buffers without
warnings. This commit adds const to all function signatures and fixes
the one assignment where the pointer is copied to a non-const pointer.

Signed-off-by: Ed Schaller <[email protected]>
  • Loading branch information
schallee authored and vathpela committed Jan 29, 2024
1 parent 6380534 commit ab3cf61
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/efivarfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ efivarfs_del_variable(efi_guid_t guid, const char *name)
}

static int
efivarfs_set_variable(efi_guid_t guid, const char *name, uint8_t *data,
efivarfs_set_variable(efi_guid_t guid, const char *name, const uint8_t *data,
size_t data_size, uint32_t attributes, mode_t mode)
{
char *path;
Expand Down Expand Up @@ -471,7 +471,7 @@ efivarfs_set_variable(efi_guid_t guid, const char *name, uint8_t *data,
}

static int
efivarfs_append_variable(efi_guid_t guid, const char *name, uint8_t *data,
efivarfs_append_variable(efi_guid_t guid, const char *name, const uint8_t *data,
size_t data_size, uint32_t attributes)
{
int rc;
Expand Down
6 changes: 2 additions & 4 deletions src/generics.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ close_dir(void)
* -- pjones */
static int UNUSED FLATTEN
generic_append_variable(efi_guid_t guid, const char *name,
uint8_t *new_data, size_t new_data_size,
const uint8_t *new_data, size_t new_data_size,
uint32_t new_attributes)
{
int rc;
Expand Down Expand Up @@ -157,10 +157,8 @@ generic_append_variable(efi_guid_t guid, const char *name,
free(d);
free(data);
} else if (rc < 0 && errno == ENOENT) {
data = new_data;
data_size = new_data_size;
attributes = new_attributes & ~EFI_VARIABLE_APPEND_WRITE;
rc = efi_set_variable(guid, name, data, data_size,
rc = efi_set_variable(guid, name, new_data, new_data_size,
attributes, 0600);
}
if (rc < 0)
Expand Down
4 changes: 2 additions & 2 deletions src/include/efivar/efivar.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ extern int efi_get_variable(efi_guid_t guid, const char *name, uint8_t **data,
extern int efi_del_variable(efi_guid_t guid, const char *name)
__attribute__((__nonnull__ (2)));
extern int efi_set_variable(efi_guid_t guid, const char *name,
uint8_t *data, size_t data_size,
const uint8_t *data, size_t data_size,
uint32_t attributes, mode_t mode)
__attribute__((__nonnull__ (2, 3)));
extern int efi_append_variable(efi_guid_t guid, const char *name,
uint8_t *data, size_t data_size,
const uint8_t *data, size_t data_size,
uint32_t attributes)
__attribute__((__nonnull__ (2, 3)));
extern int efi_get_next_variable_name(efi_guid_t **guid, char **name)
Expand Down
10 changes: 5 additions & 5 deletions src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct efi_var_operations *ops = NULL;

VERSION(_efi_set_variable, _efi_set_variable@libefivar.so.0)
int NONNULL(2, 3) PUBLIC
_efi_set_variable(efi_guid_t guid, const char *name, uint8_t *data,
_efi_set_variable(efi_guid_t guid, const char *name, const uint8_t *data,
size_t data_size, uint32_t attributes)
{
int rc;
Expand All @@ -47,7 +47,7 @@ _efi_set_variable(efi_guid_t guid, const char *name, uint8_t *data,

VERSION(_efi_set_variable_variadic, efi_set_variable@libefivar.so.0)
int NONNULL(2, 3) PUBLIC
_efi_set_variable_variadic(efi_guid_t guid, const char *name, uint8_t *data,
_efi_set_variable_variadic(efi_guid_t guid, const char *name, const uint8_t *data,
size_t data_size, uint32_t attributes, ...)
{
int rc;
Expand All @@ -64,7 +64,7 @@ _efi_set_variable_variadic(efi_guid_t guid, const char *name, uint8_t *data,

VERSION(_efi_set_variable_mode,efi_set_variable@@LIBEFIVAR_0.24)
int NONNULL(2, 3) PUBLIC
_efi_set_variable_mode(efi_guid_t guid, const char *name, uint8_t *data,
_efi_set_variable_mode(efi_guid_t guid, const char *name, const uint8_t *data,
size_t data_size, uint32_t attributes, mode_t mode)
{
int rc;
Expand All @@ -82,12 +82,12 @@ _efi_set_variable_mode(efi_guid_t guid, const char *name, uint8_t *data,
}

int NONNULL(2, 3) PUBLIC
efi_set_variable(efi_guid_t guid, const char *name, uint8_t *data,
efi_set_variable(efi_guid_t guid, const char *name, const uint8_t *data,
size_t data_size, uint32_t attributes, mode_t mode)
ALIAS(_efi_set_variable_mode);

int NONNULL(2, 3) PUBLIC
efi_append_variable(efi_guid_t guid, const char *name, uint8_t *data,
efi_append_variable(efi_guid_t guid, const char *name, const uint8_t *data,
size_t data_size, uint32_t attributes)
{
int rc;
Expand Down
4 changes: 2 additions & 2 deletions src/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct efi_variable {
struct efi_var_operations {
char name[NAME_MAX];
int (*probe)(void);
int (*set_variable)(efi_guid_t guid, const char *name, uint8_t *data,
int (*set_variable)(efi_guid_t guid, const char *name, const uint8_t *data,
size_t data_size, uint32_t attributes, mode_t mode);
int (*del_variable)(efi_guid_t guid, const char *name);
int (*get_variable)(efi_guid_t guid, const char *name, uint8_t **data,
Expand All @@ -37,7 +37,7 @@ struct efi_var_operations {
size_t *size);
int (*get_next_variable_name)(efi_guid_t **guid, char **name);
int (*append_variable)(efi_guid_t guid, const char *name,
uint8_t *data, size_t data_size,
const uint8_t *data, size_t data_size,
uint32_t attributes);
int (*chmod_variable)(efi_guid_t guid, const char *name, mode_t mode);
};
Expand Down
2 changes: 1 addition & 1 deletion src/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ vars_chmod_variable(efi_guid_t guid, const char *name, mode_t mode)
}

static int
vars_set_variable(efi_guid_t guid, const char *name, uint8_t *data,
vars_set_variable(efi_guid_t guid, const char *name, const uint8_t *data,
size_t data_size, uint32_t attributes, mode_t mode)
{
int errno_value;
Expand Down

0 comments on commit ab3cf61

Please sign in to comment.