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