|
|
ac3a84 |
From 2ccf2637e7b3caa147962976178bb347fa227946 Mon Sep 17 00:00:00 2001
|
|
|
ac3a84 |
From: Jan Janssen <medhefgo@web.de>
|
|
|
ac3a84 |
Date: Tue, 22 Nov 2022 16:03:03 +0100
|
|
|
ac3a84 |
Subject: [PATCH] boot: Use xstr8_to_16
|
|
|
ac3a84 |
|
|
|
ac3a84 |
(cherry picked from commit aee515bbb58496272a6d975858aa26a355c4fb90)
|
|
|
ac3a84 |
|
|
|
ac3a84 |
Related: #2138081
|
|
|
ac3a84 |
---
|
|
|
ac3a84 |
src/boot/efi/boot.c | 30 +++++++++++++++---------------
|
|
|
ac3a84 |
src/boot/efi/linux.c | 2 +-
|
|
|
ac3a84 |
src/boot/efi/measure.c | 2 +-
|
|
|
ac3a84 |
src/boot/efi/util.c | 30 ------------------------------
|
|
|
ac3a84 |
src/boot/efi/util.h | 1 -
|
|
|
ac3a84 |
5 files changed, 17 insertions(+), 48 deletions(-)
|
|
|
ac3a84 |
|
|
|
ac3a84 |
diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c
|
|
|
ac3a84 |
index db6ca97df4..013df67e49 100644
|
|
|
ac3a84 |
--- a/src/boot/efi/boot.c
|
|
|
ac3a84 |
+++ b/src/boot/efi/boot.c
|
|
|
ac3a84 |
@@ -1205,7 +1205,7 @@ static void config_defaults_load_from_file(Config *config, char *content) {
|
|
|
ac3a84 |
continue;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
free(config->entry_default_config);
|
|
|
ac3a84 |
- config->entry_default_config = xstra_to_str(value);
|
|
|
ac3a84 |
+ config->entry_default_config = xstr8_to_16(value);
|
|
|
ac3a84 |
continue;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
@@ -1440,25 +1440,25 @@ static void config_entry_add_type1(
|
|
|
ac3a84 |
while ((line = line_get_key_value(content, " \t", &pos, &key, &value))) {
|
|
|
ac3a84 |
if (streq8(key, "title")) {
|
|
|
ac3a84 |
free(entry->title);
|
|
|
ac3a84 |
- entry->title = xstra_to_str(value);
|
|
|
ac3a84 |
+ entry->title = xstr8_to_16(value);
|
|
|
ac3a84 |
continue;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
if (streq8(key, "sort-key")) {
|
|
|
ac3a84 |
free(entry->sort_key);
|
|
|
ac3a84 |
- entry->sort_key = xstra_to_str(value);
|
|
|
ac3a84 |
+ entry->sort_key = xstr8_to_16(value);
|
|
|
ac3a84 |
continue;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
if (streq8(key, "version")) {
|
|
|
ac3a84 |
free(entry->version);
|
|
|
ac3a84 |
- entry->version = xstra_to_str(value);
|
|
|
ac3a84 |
+ entry->version = xstr8_to_16(value);
|
|
|
ac3a84 |
continue;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
if (streq8(key, "machine-id")) {
|
|
|
ac3a84 |
free(entry->machine_id);
|
|
|
ac3a84 |
- entry->machine_id = xstra_to_str(value);
|
|
|
ac3a84 |
+ entry->machine_id = xstr8_to_16(value);
|
|
|
ac3a84 |
continue;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
@@ -1511,7 +1511,7 @@ static void config_entry_add_type1(
|
|
|
ac3a84 |
if (streq8(key, "options")) {
|
|
|
ac3a84 |
_cleanup_free_ char16_t *new = NULL;
|
|
|
ac3a84 |
|
|
|
ac3a84 |
- new = xstra_to_str(value);
|
|
|
ac3a84 |
+ new = xstr8_to_16(value);
|
|
|
ac3a84 |
if (entry->options) {
|
|
|
ac3a84 |
char16_t *s = xpool_print(L"%s %s", entry->options, new);
|
|
|
ac3a84 |
free(entry->options);
|
|
|
ac3a84 |
@@ -2157,49 +2157,49 @@ static void config_entry_add_unified(
|
|
|
ac3a84 |
while ((line = line_get_key_value(content, "=", &pos, &key, &value))) {
|
|
|
ac3a84 |
if (streq8(key, "PRETTY_NAME")) {
|
|
|
ac3a84 |
free(os_pretty_name);
|
|
|
ac3a84 |
- os_pretty_name = xstra_to_str(value);
|
|
|
ac3a84 |
+ os_pretty_name = xstr8_to_16(value);
|
|
|
ac3a84 |
continue;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
if (streq8(key, "IMAGE_ID")) {
|
|
|
ac3a84 |
free(os_image_id);
|
|
|
ac3a84 |
- os_image_id = xstra_to_str(value);
|
|
|
ac3a84 |
+ os_image_id = xstr8_to_16(value);
|
|
|
ac3a84 |
continue;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
if (streq8(key, "NAME")) {
|
|
|
ac3a84 |
free(os_name);
|
|
|
ac3a84 |
- os_name = xstra_to_str(value);
|
|
|
ac3a84 |
+ os_name = xstr8_to_16(value);
|
|
|
ac3a84 |
continue;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
if (streq8(key, "ID")) {
|
|
|
ac3a84 |
free(os_id);
|
|
|
ac3a84 |
- os_id = xstra_to_str(value);
|
|
|
ac3a84 |
+ os_id = xstr8_to_16(value);
|
|
|
ac3a84 |
continue;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
if (streq8(key, "IMAGE_VERSION")) {
|
|
|
ac3a84 |
free(os_image_version);
|
|
|
ac3a84 |
- os_image_version = xstra_to_str(value);
|
|
|
ac3a84 |
+ os_image_version = xstr8_to_16(value);
|
|
|
ac3a84 |
continue;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
if (streq8(key, "VERSION")) {
|
|
|
ac3a84 |
free(os_version);
|
|
|
ac3a84 |
- os_version = xstra_to_str(value);
|
|
|
ac3a84 |
+ os_version = xstr8_to_16(value);
|
|
|
ac3a84 |
continue;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
if (streq8(key, "VERSION_ID")) {
|
|
|
ac3a84 |
free(os_version_id);
|
|
|
ac3a84 |
- os_version_id = xstra_to_str(value);
|
|
|
ac3a84 |
+ os_version_id = xstr8_to_16(value);
|
|
|
ac3a84 |
continue;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
if (streq8(key, "BUILD_ID")) {
|
|
|
ac3a84 |
free(os_build_id);
|
|
|
ac3a84 |
- os_build_id = xstra_to_str(value);
|
|
|
ac3a84 |
+ os_build_id = xstr8_to_16(value);
|
|
|
ac3a84 |
continue;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
@@ -2248,7 +2248,7 @@ static void config_entry_add_unified(
|
|
|
ac3a84 |
if (content[szs[SECTION_CMDLINE] - 1] == '\n')
|
|
|
ac3a84 |
content[szs[SECTION_CMDLINE] - 1] = '\0';
|
|
|
ac3a84 |
|
|
|
ac3a84 |
- entry->options = xstra_to_str(content);
|
|
|
ac3a84 |
+ entry->options = xstr8_to_16(content);
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
diff --git a/src/boot/efi/linux.c b/src/boot/efi/linux.c
|
|
|
ac3a84 |
index dd7eb48c8c..668510fca3 100644
|
|
|
ac3a84 |
--- a/src/boot/efi/linux.c
|
|
|
ac3a84 |
+++ b/src/boot/efi/linux.c
|
|
|
ac3a84 |
@@ -133,7 +133,7 @@ EFI_STATUS linux_exec(
|
|
|
ac3a84 |
return log_error_status_stall(err, u"Error getting kernel loaded image protocol: %r", err);
|
|
|
ac3a84 |
|
|
|
ac3a84 |
if (cmdline) {
|
|
|
ac3a84 |
- loaded_image->LoadOptions = xstra_to_str(cmdline);
|
|
|
ac3a84 |
+ loaded_image->LoadOptions = xstrn8_to_16(cmdline, cmdline_len);
|
|
|
ac3a84 |
loaded_image->LoadOptionsSize = strsize16(loaded_image->LoadOptions);
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
diff --git a/src/boot/efi/measure.c b/src/boot/efi/measure.c
|
|
|
ac3a84 |
index 9a16920787..6da07d917e 100644
|
|
|
ac3a84 |
--- a/src/boot/efi/measure.c
|
|
|
ac3a84 |
+++ b/src/boot/efi/measure.c
|
|
|
ac3a84 |
@@ -187,7 +187,7 @@ EFI_STATUS tpm_log_event_ascii(uint32_t pcrindex, EFI_PHYSICAL_ADDRESS buffer, U
|
|
|
ac3a84 |
_cleanup_free_ char16_t *c = NULL;
|
|
|
ac3a84 |
|
|
|
ac3a84 |
if (description)
|
|
|
ac3a84 |
- c = xstra_to_str(description);
|
|
|
ac3a84 |
+ c = xstr8_to_16(description);
|
|
|
ac3a84 |
|
|
|
ac3a84 |
return tpm_log_event(pcrindex, buffer, buffer_size, c, ret_measured);
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c
|
|
|
ac3a84 |
index 3eba2ade07..b727d6de7e 100644
|
|
|
ac3a84 |
--- a/src/boot/efi/util.c
|
|
|
ac3a84 |
+++ b/src/boot/efi/util.c
|
|
|
ac3a84 |
@@ -303,36 +303,6 @@ static int utf8_to_16(const char *stra, char16_t *c) {
|
|
|
ac3a84 |
return len;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
-char16_t *xstra_to_str(const char *stra) {
|
|
|
ac3a84 |
- UINTN strlen;
|
|
|
ac3a84 |
- UINTN len;
|
|
|
ac3a84 |
- UINTN i;
|
|
|
ac3a84 |
- char16_t *str;
|
|
|
ac3a84 |
-
|
|
|
ac3a84 |
- assert(stra);
|
|
|
ac3a84 |
-
|
|
|
ac3a84 |
- len = strlen8(stra);
|
|
|
ac3a84 |
- str = xnew(char16_t, len + 1);
|
|
|
ac3a84 |
-
|
|
|
ac3a84 |
- strlen = 0;
|
|
|
ac3a84 |
- i = 0;
|
|
|
ac3a84 |
- while (i < len) {
|
|
|
ac3a84 |
- int utf8len;
|
|
|
ac3a84 |
-
|
|
|
ac3a84 |
- utf8len = utf8_to_16(stra + i, str + strlen);
|
|
|
ac3a84 |
- if (utf8len <= 0) {
|
|
|
ac3a84 |
- /* invalid utf8 sequence, skip the garbage */
|
|
|
ac3a84 |
- i++;
|
|
|
ac3a84 |
- continue;
|
|
|
ac3a84 |
- }
|
|
|
ac3a84 |
-
|
|
|
ac3a84 |
- strlen++;
|
|
|
ac3a84 |
- i += utf8len;
|
|
|
ac3a84 |
- }
|
|
|
ac3a84 |
- str[strlen] = '\0';
|
|
|
ac3a84 |
- return str;
|
|
|
ac3a84 |
-}
|
|
|
ac3a84 |
-
|
|
|
ac3a84 |
char16_t *xstra_to_path(const char *stra) {
|
|
|
ac3a84 |
char16_t *str;
|
|
|
ac3a84 |
UINTN strlen;
|
|
|
ac3a84 |
diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h
|
|
|
ac3a84 |
index 994cf52ad6..d78feac39c 100644
|
|
|
ac3a84 |
--- a/src/boot/efi/util.h
|
|
|
ac3a84 |
+++ b/src/boot/efi/util.h
|
|
|
ac3a84 |
@@ -113,7 +113,6 @@ EFI_STATUS efivar_get_uint64_le(const EFI_GUID *vendor, const char16_t *name, ui
|
|
|
ac3a84 |
EFI_STATUS efivar_get_boolean_u8(const EFI_GUID *vendor, const char16_t *name, bool *ret);
|
|
|
ac3a84 |
|
|
|
ac3a84 |
char16_t *xstra_to_path(const char *stra);
|
|
|
ac3a84 |
-char16_t *xstra_to_str(const char *stra);
|
|
|
ac3a84 |
|
|
|
ac3a84 |
EFI_STATUS file_read(EFI_FILE *dir, const char16_t *name, UINTN off, UINTN size, char **content, UINTN *content_size);
|
|
|
ac3a84 |
|