From 7783ab5df1a17a4d417661047e48599ac685d2a8 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Wed, 25 May 2022 11:05:19 +0200 Subject: [PATCH] boot: Use xstrdup8/16 Note that xstrdup is now safe to call with a NULL pointer and will just return NULL in that case. --- src/boot/efi/boot.c | 42 +++++++++++++++++++++--------------------- src/boot/efi/cpio.c | 2 +- src/boot/efi/util.h | 1 - 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index e3964033c27..71f12279231 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -418,11 +418,11 @@ static CHAR16 *update_timeout_efivar(UINT32 *t, BOOLEAN inc) { switch (*t) { case TIMEOUT_UNSET: - return xstrdup(L"Menu timeout defined by configuration file."); + return xstrdup16(u"Menu timeout defined by configuration file."); case TIMEOUT_MENU_FORCE: - return xstrdup(L"Timeout disabled, menu will always be shown."); + return xstrdup16(u"Timeout disabled, menu will always be shown."); case TIMEOUT_MENU_HIDDEN: - return xstrdup(L"Menu disabled. Hold down key at bootup to show menu."); + return xstrdup16(u"Menu disabled. Hold down key at bootup to show menu."); default: return xpool_print(L"Menu timeout set to %u s.", *t); } @@ -861,7 +861,7 @@ static BOOLEAN menu_run( case KEYPRESS(0, 0, 'H'): case KEYPRESS(0, 0, '?'): /* This must stay below 80 characters! Q/v/Ctrl+l/f deliberately not advertised. */ - status = xstrdup(L"(d)efault (t/T)timeout (e)dit (r/R)resolution (p)rint (h)elp"); + status = xstrdup16(u"(d)efault (t/T)timeout (e)dit (r/R)resolution (p)rint (h)elp"); break; case KEYPRESS(0, 0, 'Q'): @@ -873,13 +873,13 @@ static BOOLEAN menu_run( case KEYPRESS(0, 0, 'D'): if (config->idx_default_efivar != idx_highlight) { FreePool(config->entry_default_efivar); - config->entry_default_efivar = xstrdup(config->entries[idx_highlight]->id); + config->entry_default_efivar = xstrdup16(config->entries[idx_highlight]->id); config->idx_default_efivar = idx_highlight; - status = xstrdup(L"Default boot entry selected."); + status = xstrdup16(u"Default boot entry selected."); } else { config->entry_default_efivar = mfree(config->entry_default_efivar); config->idx_default_efivar = IDX_INVALID; - status = xstrdup(L"Default boot entry cleared."); + status = xstrdup16(u"Default boot entry cleared."); } config->use_saved_entry_efivar = FALSE; refresh = TRUE; @@ -1360,13 +1360,13 @@ good: entry->tries_left = left; entry->tries_done = done; - entry->path = xstrdup(path); - entry->current_name = xstrdup(file); + entry->path = xstrdup16(path); + entry->current_name = xstrdup16(file); next_left = left <= 0 ? 0 : left - 1; next_done = done >= (UINTN) -2 ? (UINTN) -2 : done + 1; - prefix = xstrdup(file); + prefix = xstrdup16(file); prefix[i] = 0; entry->next_name = xpool_print(L"%s+%" PRIuN L"-%" PRIuN L"%s", prefix, next_left, next_done, strempty(suffix)); @@ -1547,7 +1547,7 @@ static void config_entry_add_type1( return; entry->device = device; - entry->id = xstrdup(file); + entry->id = xstrdup16(file); strtolower16(entry->id); config_add_entry(config, entry); @@ -1792,7 +1792,7 @@ static void config_title_generate(Config *config) { for (UINTN i = 0; i < config->entry_count; i++) { assert(!config->entries[i]->title_show); unique[i] = TRUE; - config->entries[i]->title_show = xstrdup(config->entries[i]->title ?: config->entries[i]->id); + config->entries[i]->title_show = xstrdup16(config->entries[i]->title ?: config->entries[i]->id); } if (entries_unique(config->entries, unique, config->entry_count)) @@ -1911,11 +1911,11 @@ static ConfigEntry *config_entry_add_loader_auto( ConfigEntry *entry = xnew(ConfigEntry, 1); *entry = (ConfigEntry) { - .id = xstrdup(id), + .id = xstrdup16(id), .type = LOADER_AUTO, - .title = xstrdup(title), + .title = xstrdup16(title), .device = device, - .loader = xstrdup(loader), + .loader = xstrdup16(loader), .key = key, .tries_done = UINTN_MAX, .tries_left = UINTN_MAX, @@ -2197,13 +2197,13 @@ static void config_entry_add_unified( ConfigEntry *entry = xnew(ConfigEntry, 1); *entry = (ConfigEntry) { - .id = xstrdup(f->FileName), + .id = xstrdup16(f->FileName), .type = LOADER_UNIFIED_LINUX, - .title = xstrdup(good_name), - .version = good_version ? xstrdup(good_version) : NULL, + .title = xstrdup16(good_name), + .version = xstrdup16(good_version), .device = device, .loader = xpool_print(L"\\EFI\\Linux\\%s", f->FileName), - .sort_key = good_sort_key ? xstrdup(good_sort_key) : NULL, + .sort_key = xstrdup16(good_sort_key), .key = 'l', .tries_done = UINTN_MAX, .tries_left = UINTN_MAX, @@ -2545,8 +2545,8 @@ static void config_load_all_entries( if (config->auto_firmware && FLAGS_SET(get_os_indications_supported(), EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) { ConfigEntry *entry = xnew(ConfigEntry, 1); *entry = (ConfigEntry) { - .id = xstrdup(L"auto-reboot-to-firmware-setup"), - .title = xstrdup(L"Reboot Into Firmware Interface"), + .id = xstrdup16(u"auto-reboot-to-firmware-setup"), + .title = xstrdup16(u"Reboot Into Firmware Interface"), .call = reboot_into_firmware, .tries_done = UINTN_MAX, .tries_left = UINTN_MAX, diff --git a/src/boot/efi/cpio.c b/src/boot/efi/cpio.c index 18689d9d6b7..66ef5da3138 100644 --- a/src/boot/efi/cpio.c +++ b/src/boot/efi/cpio.c @@ -391,7 +391,7 @@ EFI_STATUS pack_cpio( if (strlen16(dirent->FileName) > 255) /* Max filename size on Linux */ continue; - d = xstrdup(dirent->FileName); + d = xstrdup16(dirent->FileName); if (n_items+2 > n_allocated) { UINTN m; diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index fcfadf3a6eb..06c298d776d 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -41,7 +41,6 @@ assert_cc(sizeof(int) == sizeof(UINT32)); #define xallocate_zero_pool(size) ASSERT_SE_PTR(AllocateZeroPool(size)) #define xreallocate_pool(p, old_size, new_size) ASSERT_SE_PTR(ReallocatePool((p), (old_size), (new_size))) #define xpool_print(fmt, ...) ((CHAR16 *) ASSERT_SE_PTR(PoolPrint((fmt), ##__VA_ARGS__))) -#define xstrdup(str) ((CHAR16 *) ASSERT_SE_PTR(StrDuplicate(str))) #define xnew(type, n) xnew_alloc(type, (n), xallocate_pool) #define xnew0(type, n) xnew_alloc(type, (n), xallocate_zero_pool) -- 2.47.3