diff options
author | Jan Janssen <medhefgo@web.de> | 2021-11-15 12:31:48 +0100 |
---|---|---|
committer | Jan Janssen <medhefgo@web.de> | 2021-11-29 16:20:45 +0100 |
commit | 4f94341504b210aff70e6eae1b74f0e54f5bbdbc (patch) | |
tree | 4fbf704c38c2e01365691e2a17c3643e0bc02798 | |
parent | da76f890aab165ac194b21ac41289df70d0b6a3f (diff) | |
download | systemd-4f94341504b210aff70e6eae1b74f0e54f5bbdbc.tar.gz |
sd-boot: Make stra_to_path/stra_to_str non-failing
-rw-r--r-- | src/boot/efi/boot.c | 42 | ||||
-rw-r--r-- | src/boot/efi/linux.c | 8 | ||||
-rw-r--r-- | src/boot/efi/util.c | 12 | ||||
-rw-r--r-- | src/boot/efi/util.h | 4 |
4 files changed, 28 insertions, 38 deletions
diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 05aecabc8a..23f9980315 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -1096,7 +1096,7 @@ static void config_defaults_load_from_file(Config *config, CHAR8 *content) { else { _cleanup_freepool_ CHAR16 *s = NULL; - s = stra_to_str(value); + s = xstra_to_str(value); config->timeout_sec_config = MIN(Atoi(s), TIMEOUT_TYPE_MAX); } config->timeout_sec = config->timeout_sec_config; @@ -1109,7 +1109,7 @@ static void config_defaults_load_from_file(Config *config, CHAR8 *content) { continue; } FreePool(config->entry_default_config); - config->entry_default_config = stra_to_str(value); + config->entry_default_config = xstra_to_str(value); continue; } @@ -1144,7 +1144,7 @@ static void config_defaults_load_from_file(Config *config, CHAR8 *content) { else { _cleanup_freepool_ CHAR16 *s = NULL; - s = stra_to_str(value); + s = xstra_to_str(value); config->console_mode = MIN(Atoi(s), (UINTN)CONSOLE_MODE_RANGE_MAX); } @@ -1377,26 +1377,26 @@ static void config_entry_add_from_file( while ((line = line_get_key_value(content, (CHAR8 *)" \t", &pos, &key, &value))) { if (strcmpa((CHAR8 *)"title", key) == 0) { FreePool(entry->title); - entry->title = stra_to_str(value); + entry->title = xstra_to_str(value); continue; } if (strcmpa((CHAR8 *)"version", key) == 0) { FreePool(entry->version); - entry->version = stra_to_str(value); + entry->version = xstra_to_str(value); continue; } if (strcmpa((CHAR8 *)"machine-id", key) == 0) { FreePool(entry->machine_id); - entry->machine_id = stra_to_str(value); + entry->machine_id = xstra_to_str(value); continue; } if (strcmpa((CHAR8 *)"linux", key) == 0) { FreePool(entry->loader); entry->type = LOADER_LINUX; - entry->loader = stra_to_path(value); + entry->loader = xstra_to_path(value); entry->key = 'l'; continue; } @@ -1404,7 +1404,7 @@ static void config_entry_add_from_file( if (strcmpa((CHAR8 *)"efi", key) == 0) { entry->type = LOADER_EFI; FreePool(entry->loader); - entry->loader = stra_to_path(value); + entry->loader = xstra_to_path(value); /* do not add an entry for ourselves */ if (loaded_image_path && StriCmp(entry->loader, loaded_image_path) == 0) { @@ -1425,14 +1425,14 @@ static void config_entry_add_from_file( if (strcmpa((CHAR8 *)"devicetree", key) == 0) { FreePool(entry->devicetree); - entry->devicetree = stra_to_path(value); + entry->devicetree = xstra_to_path(value); continue; } if (strcmpa((CHAR8 *)"initrd", key) == 0) { _cleanup_freepool_ CHAR16 *new = NULL; - new = stra_to_path(value); + new = xstra_to_path(value); if (initrd) { CHAR16 *s; @@ -1448,7 +1448,7 @@ static void config_entry_add_from_file( if (strcmpa((CHAR8 *)"options", key) == 0) { _cleanup_freepool_ CHAR16 *new = NULL; - new = stra_to_str(value); + new = xstra_to_str(value); if (entry->options) { CHAR16 *s; @@ -2057,49 +2057,49 @@ static void config_entry_add_linux( while ((line = line_get_key_value(content, (CHAR8 *)"=", &pos, &key, &value))) { if (strcmpa((const CHAR8*) "PRETTY_NAME", key) == 0) { FreePool(os_pretty_name); - os_pretty_name = stra_to_str(value); + os_pretty_name = xstra_to_str(value); continue; } if (strcmpa((const CHAR8*) "IMAGE_ID", key) == 0) { FreePool(os_image_id); - os_image_id = stra_to_str(value); + os_image_id = xstra_to_str(value); continue; } if (strcmpa((const CHAR8*) "NAME", key) == 0) { FreePool(os_name); - os_name = stra_to_str(value); + os_name = xstra_to_str(value); continue; } if (strcmpa((const CHAR8*) "ID", key) == 0) { FreePool(os_id); - os_id = stra_to_str(value); + os_id = xstra_to_str(value); continue; } if (strcmpa((const CHAR8*) "IMAGE_VERSION", key) == 0) { FreePool(os_image_version); - os_image_version = stra_to_str(value); + os_image_version = xstra_to_str(value); continue; } if (strcmpa((const CHAR8*) "VERSION", key) == 0) { FreePool(os_version); - os_version = stra_to_str(value); + os_version = xstra_to_str(value); continue; } if (strcmpa((const CHAR8*) "VERSION_ID", key) == 0) { FreePool(os_version_id); - os_version_id = stra_to_str(value); + os_version_id = xstra_to_str(value); continue; } if (strcmpa((const CHAR8*) "BUILD_ID", key) == 0) { FreePool(os_build_id); - os_build_id = stra_to_str(value); + os_build_id = xstra_to_str(value); continue; } } @@ -2142,9 +2142,7 @@ static void config_entry_add_linux( if (content[szs[SECTION_CMDLINE] - 1] == '\n') content[szs[SECTION_CMDLINE] - 1] = '\0'; - entry->options = stra_to_str(content); - if (!entry->options) - return (void) log_oom(); + entry->options = xstra_to_str(content); } } } diff --git a/src/boot/efi/linux.c b/src/boot/efi/linux.c index c20ddbdfc6..8e3afb795b 100644 --- a/src/boot/efi/linux.c +++ b/src/boot/efi/linux.c @@ -46,13 +46,9 @@ static EFI_STATUS loaded_image_register( .ImageSize = linux_length }; - /* if a cmdline is set convert it to UTF16 */ + /* if a cmdline is set convert it to UCS2 */ if (cmdline) { - loaded_image->LoadOptions = stra_to_str(cmdline); - if (!loaded_image->LoadOptions) { - loaded_image = loaded_image_free(loaded_image); - return EFI_OUT_OF_RESOURCES; - } + loaded_image->LoadOptions = xstra_to_str(cmdline); loaded_image->LoadOptionsSize = StrSize(loaded_image->LoadOptions); } diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index 4d981ca7e5..aa3c249562 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -358,7 +358,7 @@ static INTN utf8_to_16(const CHAR8 *stra, CHAR16 *c) { return len; } -CHAR16 *stra_to_str(const CHAR8 *stra) { +CHAR16 *xstra_to_str(const CHAR8 *stra) { UINTN strlen; UINTN len; UINTN i; @@ -367,9 +367,7 @@ CHAR16 *stra_to_str(const CHAR8 *stra) { assert(stra); len = strlena(stra); - str = AllocatePool((len + 1) * sizeof(CHAR16)); - if (!str) - return NULL; + str = xnew(CHAR16, len + 1); strlen = 0; i = 0; @@ -390,7 +388,7 @@ CHAR16 *stra_to_str(const CHAR8 *stra) { return str; } -CHAR16 *stra_to_path(const CHAR8 *stra) { +CHAR16 *xstra_to_path(const CHAR8 *stra) { CHAR16 *str; UINTN strlen; UINTN len; @@ -399,9 +397,7 @@ CHAR16 *stra_to_path(const CHAR8 *stra) { assert(stra); len = strlena(stra); - str = AllocatePool((len + 2) * sizeof(CHAR16)); - if (!str) - return NULL; + str = xnew(CHAR16, len + 2); str[0] = '\\'; strlen = 1; diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index 9505d3bf21..d5f32dbb38 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -68,8 +68,8 @@ EFI_STATUS efivar_get_uint64_le(const EFI_GUID *vendor, const CHAR16 *name, UINT EFI_STATUS efivar_get_boolean_u8(const EFI_GUID *vendor, const CHAR16 *name, BOOLEAN *ret); CHAR8 *strchra(const CHAR8 *s, CHAR8 c); -CHAR16 *stra_to_path(const CHAR8 *stra); -CHAR16 *stra_to_str(const CHAR8 *stra); +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); |