summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Janssen <medhefgo@web.de>2022-01-13 12:34:35 +0100
committerJan Janssen <medhefgo@web.de>2022-01-13 14:26:43 +0100
commit85eb489e231c9c536a05ea071bd35796f08b0ada (patch)
tree03108e0a2f7052bd552975d0dc0f241aa39d3542
parentboot: Fix invalid free (diff)
downloadsystemd-85eb489e231c9c536a05ea071bd35796f08b0ada.tar.xz
systemd-85eb489e231c9c536a05ea071bd35796f08b0ada.zip
boot: Use EFI_FILE* instead of EFI_FILE_HANDLE
They are both the same, but the former is shorter and also closer to how file handles are represented in the UEFI spec.
Diffstat (limited to '')
-rw-r--r--src/boot/efi/boot.c29
-rw-r--r--src/boot/efi/cpio.c2
-rw-r--r--src/boot/efi/devicetree.c5
-rw-r--r--src/boot/efi/devicetree.h2
-rw-r--r--src/boot/efi/drivers.c4
-rw-r--r--src/boot/efi/drivers.h2
-rw-r--r--src/boot/efi/pe.c2
-rw-r--r--src/boot/efi/random-seed.c2
-rw-r--r--src/boot/efi/util.c14
-rw-r--r--src/boot/efi/util.h10
10 files changed, 32 insertions, 40 deletions
diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c
index 96a41bbb50..ce901e7cb6 100644
--- a/src/boot/efi/boot.c
+++ b/src/boot/efi/boot.c
@@ -1309,12 +1309,9 @@ good:
entry->next_name = xpool_print(L"%s+%u-%u%s", prefix, next_left, next_done, suffix ?: L"");
}
-static void config_entry_bump_counters(
- ConfigEntry *entry,
- EFI_FILE_HANDLE root_dir) {
-
+static void config_entry_bump_counters(ConfigEntry *entry, EFI_FILE *root_dir) {
_cleanup_freepool_ CHAR16* old_path = NULL, *new_path = NULL;
- _cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
+ _cleanup_(file_closep) EFI_FILE *handle = NULL;
_cleanup_freepool_ EFI_FILE_INFO *file_info = NULL;
UINTN file_info_size;
EFI_STATUS err;
@@ -1375,7 +1372,6 @@ static void config_entry_add_from_file(
UINTN pos = 0;
CHAR8 *key, *value;
EFI_STATUS err;
- EFI_FILE_HANDLE handle;
_cleanup_freepool_ CHAR16 *initrd = NULL;
assert(config);
@@ -1483,10 +1479,10 @@ static void config_entry_add_from_file(
return;
/* check existence */
+ _cleanup_(file_closep) EFI_FILE *handle = NULL;
err = root_dir->Open(root_dir, &handle, entry->loader, EFI_FILE_MODE_READ, 0ULL);
if (EFI_ERROR(err))
return;
- handle->Close(handle);
/* add initrd= to options */
if (entry->type == LOADER_LINUX && initrd) {
@@ -1571,7 +1567,7 @@ static void config_load_entries(
EFI_FILE *root_dir,
const CHAR16 *loaded_image_path) {
- _cleanup_(file_handle_closep) EFI_FILE_HANDLE entries_dir = NULL;
+ _cleanup_(file_closep) EFI_FILE *entries_dir = NULL;
_cleanup_freepool_ EFI_FILE_INFO *f = NULL;
UINTN f_size = 0;
EFI_STATUS err;
@@ -1888,9 +1884,6 @@ static ConfigEntry *config_entry_add_loader_auto(
const CHAR16 *title,
const CHAR16 *loader) {
- EFI_FILE_HANDLE handle;
- EFI_STATUS err;
-
assert(config);
assert(device);
assert(root_dir);
@@ -1916,10 +1909,10 @@ static ConfigEntry *config_entry_add_loader_auto(
}
/* check existence */
- err = root_dir->Open(root_dir, &handle, (CHAR16*) loader, EFI_FILE_MODE_READ, 0ULL);
+ _cleanup_(file_closep) EFI_FILE *handle = NULL;
+ EFI_STATUS err = root_dir->Open(root_dir, &handle, (CHAR16*) loader, EFI_FILE_MODE_READ, 0ULL);
if (EFI_ERROR(err))
return NULL;
- handle->Close(handle);
return config_entry_add_loader(config, device, LOADER_AUTO, id, key, title, loader, NULL);
}
@@ -1939,7 +1932,7 @@ static void config_entry_add_osx(Config *config) {
return;
for (UINTN i = 0; i < n_handles; i++) {
- _cleanup_(file_handle_closep) EFI_FILE *root = LibOpenRoot(handles[i]);
+ _cleanup_(file_closep) EFI_FILE *root = LibOpenRoot(handles[i]);
if (!root)
continue;
@@ -2066,7 +2059,7 @@ static void config_entry_add_linux(
EFI_HANDLE *device,
EFI_FILE *root_dir) {
- _cleanup_(file_handle_closep) EFI_FILE_HANDLE linux_dir = NULL;
+ _cleanup_(file_closep) EFI_FILE *linux_dir = NULL;
_cleanup_freepool_ EFI_FILE_INFO *f = NULL;
ConfigEntry *entry;
UINTN f_size = 0;
@@ -2224,7 +2217,7 @@ static void config_load_xbootldr(
Config *config,
EFI_HANDLE *device) {
- _cleanup_(file_handle_closep) EFI_FILE *root_dir = NULL;
+ _cleanup_(file_closep) EFI_FILE *root_dir = NULL;
EFI_HANDLE new_device;
EFI_STATUS err;
@@ -2240,7 +2233,7 @@ static void config_load_xbootldr(
}
static EFI_STATUS image_start(
- EFI_FILE_HANDLE root_dir,
+ EFI_FILE *root_dir,
EFI_HANDLE parent_image,
const Config *config,
const ConfigEntry *entry) {
@@ -2456,7 +2449,7 @@ static void config_load_all_entries(
EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
_cleanup_freepool_ EFI_LOADED_IMAGE *loaded_image = NULL;
- _cleanup_(file_handle_closep) EFI_FILE *root_dir = NULL;
+ _cleanup_(file_closep) EFI_FILE *root_dir = NULL;
_cleanup_(config_free) Config config = {};
CHAR16 *loaded_image_path;
EFI_STATUS err;
diff --git a/src/boot/efi/cpio.c b/src/boot/efi/cpio.c
index 924ac35939..258755366e 100644
--- a/src/boot/efi/cpio.c
+++ b/src/boot/efi/cpio.c
@@ -316,7 +316,7 @@ EFI_STATUS pack_cpio(
void **ret_buffer,
UINTN *ret_buffer_size) {
- _cleanup_(file_handle_closep) EFI_FILE_HANDLE root = NULL, extra_dir = NULL;
+ _cleanup_(file_closep) EFI_FILE *root = NULL, *extra_dir = NULL;
UINTN dirent_size = 0, buffer_size = 0, n_items = 0, n_allocated = 0;
_cleanup_freepool_ CHAR16 *rel_dropin_dir = NULL;
_cleanup_freepool_ EFI_FILE_INFO *dirent = NULL;
diff --git a/src/boot/efi/devicetree.c b/src/boot/efi/devicetree.c
index 476843bbce..b8ba52a523 100644
--- a/src/boot/efi/devicetree.c
+++ b/src/boot/efi/devicetree.c
@@ -64,9 +64,8 @@ static EFI_STATUS devicetree_fixup(struct devicetree_state *state, UINTN len) {
return err;
}
-EFI_STATUS devicetree_install(struct devicetree_state *state,
- EFI_FILE_HANDLE root_dir, CHAR16 *name) {
- _cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
+EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir, CHAR16 *name) {
+ _cleanup_(file_closep) EFI_FILE *handle = NULL;
_cleanup_freepool_ EFI_FILE_INFO *info = NULL;
UINTN len;
EFI_STATUS err;
diff --git a/src/boot/efi/devicetree.h b/src/boot/efi/devicetree.h
index fa8a1be6ed..71ce105028 100644
--- a/src/boot/efi/devicetree.h
+++ b/src/boot/efi/devicetree.h
@@ -7,7 +7,7 @@ struct devicetree_state {
void *orig;
};
-EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE_HANDLE root_dir, CHAR16 *name);
+EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir, CHAR16 *name);
EFI_STATUS devicetree_install_from_memory(
struct devicetree_state *state, const VOID *dtb_buffer, UINTN dtb_length);
void devicetree_cleanup(struct devicetree_state *state);
diff --git a/src/boot/efi/drivers.c b/src/boot/efi/drivers.c
index 851203e694..55dd0eb33e 100644
--- a/src/boot/efi/drivers.c
+++ b/src/boot/efi/drivers.c
@@ -80,9 +80,9 @@ static EFI_STATUS reconnect(void) {
EFI_STATUS load_drivers(
EFI_HANDLE parent_image,
EFI_LOADED_IMAGE *loaded_image,
- EFI_FILE_HANDLE root_dir) {
+ EFI_FILE *root_dir) {
- _cleanup_(file_handle_closep) EFI_FILE_HANDLE drivers_dir = NULL;
+ _cleanup_(file_closep) EFI_FILE *drivers_dir = NULL;
_cleanup_freepool_ EFI_FILE_INFO *dirent = NULL;
UINTN dirent_size = 0, n_succeeded = 0;
EFI_STATUS err;
diff --git a/src/boot/efi/drivers.h b/src/boot/efi/drivers.h
index c192c6d44c..242aedcdd7 100644
--- a/src/boot/efi/drivers.h
+++ b/src/boot/efi/drivers.h
@@ -6,4 +6,4 @@
EFI_STATUS load_drivers(
EFI_HANDLE parent_image,
EFI_LOADED_IMAGE *loaded_image,
- EFI_FILE_HANDLE root_dir);
+ EFI_FILE *root_dir);
diff --git a/src/boot/efi/pe.c b/src/boot/efi/pe.c
index 2fc38f7b36..e16716498f 100644
--- a/src/boot/efi/pe.c
+++ b/src/boot/efi/pe.c
@@ -224,7 +224,7 @@ EFI_STATUS pe_file_locate_sections(
UINTN *offsets,
UINTN *sizes) {
_cleanup_freepool_ struct PeSectionHeader *section_table = NULL;
- _cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
+ _cleanup_(file_closep) EFI_FILE *handle = NULL;
struct DosFileHeader dos;
struct PeFileHeader pe;
UINTN len, section_table_len;
diff --git a/src/boot/efi/random-seed.c b/src/boot/efi/random-seed.c
index 9d8e34d1ee..b007f41f7e 100644
--- a/src/boot/efi/random-seed.c
+++ b/src/boot/efi/random-seed.c
@@ -225,7 +225,7 @@ static void validate_sha256(void) {
EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) {
_cleanup_freepool_ void *seed = NULL, *new_seed = NULL, *rng = NULL, *for_kernel = NULL, *system_token = NULL;
- _cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
+ _cleanup_(file_closep) EFI_FILE *handle = NULL;
UINTN size, rsize, wsize, system_token_size = 0;
_cleanup_freepool_ EFI_FILE_INFO *info = NULL;
EFI_STATUS err;
diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c
index db998ca8da..4fac6d3eee 100644
--- a/src/boot/efi/util.c
+++ b/src/boot/efi/util.c
@@ -435,8 +435,8 @@ CHAR8 *strchra(const CHAR8 *s, CHAR8 c) {
return NULL;
}
-EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **ret, UINTN *ret_size) {
- _cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
+EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **ret, UINTN *ret_size) {
+ _cleanup_(file_closep) EFI_FILE *handle = NULL;
_cleanup_freepool_ CHAR8 *buf = NULL;
EFI_STATUS err;
@@ -544,7 +544,7 @@ void sort_pointer_array(
}
EFI_STATUS get_file_info_harder(
- EFI_FILE_HANDLE handle,
+ EFI_FILE *handle,
EFI_FILE_INFO **ret,
UINTN *ret_size) {
@@ -577,7 +577,7 @@ EFI_STATUS get_file_info_harder(
}
EFI_STATUS readdir_harder(
- EFI_FILE_HANDLE handle,
+ EFI_FILE *handle,
EFI_FILE_INFO **buffer,
UINTN *buffer_size) {
@@ -700,11 +700,11 @@ CHAR16 **strv_free(CHAR16 **v) {
}
EFI_STATUS open_directory(
- EFI_FILE_HANDLE root,
+ EFI_FILE *root,
const CHAR16 *path,
- EFI_FILE_HANDLE *ret) {
+ EFI_FILE **ret) {
- _cleanup_(file_handle_closep) EFI_FILE_HANDLE dir = NULL;
+ _cleanup_(file_closep) EFI_FILE *dir = NULL;
_cleanup_freepool_ EFI_FILE_INFO *file_info = NULL;
EFI_STATUS err;
diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h
index 58ca44443d..0c477fccf1 100644
--- a/src/boot/efi/util.h
+++ b/src/boot/efi/util.h
@@ -71,7 +71,7 @@ CHAR8 *strchra(const CHAR8 *s, CHAR8 c);
CHAR16 *xstra_to_path(const CHAR8 *stra);
CHAR16 *xstra_to_str(const CHAR8 *stra);
-EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size);
+EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size);
static inline void free_poolp(void *p) {
void *q = *(void**) p;
@@ -84,7 +84,7 @@ static inline void free_poolp(void *p) {
#define _cleanup_freepool_ _cleanup_(free_poolp)
-static inline void file_handle_closep(EFI_FILE_HANDLE *handle) {
+static inline void file_closep(EFI_FILE **handle) {
if (!*handle)
return;
@@ -117,9 +117,9 @@ void clear_screen(UINTN attr);
typedef INTN (*compare_pointer_func_t)(const void *a, const void *b);
void sort_pointer_array(void **array, UINTN n_members, compare_pointer_func_t compare);
-EFI_STATUS get_file_info_harder(EFI_FILE_HANDLE handle, EFI_FILE_INFO **ret, UINTN *ret_size);
+EFI_STATUS get_file_info_harder(EFI_FILE *handle, EFI_FILE_INFO **ret, UINTN *ret_size);
-EFI_STATUS readdir_harder(EFI_FILE_HANDLE handle, EFI_FILE_INFO **buffer, UINTN *buffer_size);
+EFI_STATUS readdir_harder(EFI_FILE *handle, EFI_FILE_INFO **buffer, UINTN *buffer_size);
UINTN strnlena(const CHAR8 *p, UINTN maxlen);
CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz);
@@ -136,7 +136,7 @@ static inline void strv_freep(CHAR16 ***p) {
strv_free(*p);
}
-EFI_STATUS open_directory(EFI_FILE_HANDLE root_dir, const CHAR16 *path, EFI_FILE_HANDLE *ret);
+EFI_STATUS open_directory(EFI_FILE *root_dir, const CHAR16 *path, EFI_FILE **ret);
/* Conversion between EFI_PHYSICAL_ADDRESS and pointers is not obvious. The former is always 64bit, even on
* 32bit archs. And gcc complains if we cast a pointer to an integer of a different size. Hence let's do the