summaryrefslogtreecommitdiffstats
path: root/src/shared/efi-loader.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 10:23:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 10:23:34 +0000
commit35962ed6b09ac995d663aeb7ab0287743cecc24c (patch)
tree24a36570c53b15b3bd6e955054f8c4846db0e262 /src/shared/efi-loader.c
parentAdding debian version 252.22-1~deb12u1. (diff)
downloadsystemd-35962ed6b09ac995d663aeb7ab0287743cecc24c.tar.xz
systemd-35962ed6b09ac995d663aeb7ab0287743cecc24c.zip
Merging upstream version 252.23.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/shared/efi-loader.c')
-rw-r--r--src/shared/efi-loader.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/shared/efi-loader.c b/src/shared/efi-loader.c
index 1340412..b9fe26b 100644
--- a/src/shared/efi-loader.c
+++ b/src/shared/efi-loader.c
@@ -99,7 +99,8 @@ int efi_loader_get_entries(char ***ret) {
if (r < 0)
return r;
- /* The variable contains a series of individually NUL terminated UTF-16 strings. */
+ /* The variable contains a series of individually NUL terminated UTF-16 strings. We gracefully
+ * consider the final NUL byte optional (i.e. the last string may or may not end in a NUL byte).*/
for (size_t i = 0, start = 0;; i++) {
_cleanup_free_ char *decoded = NULL;
@@ -113,6 +114,11 @@ int efi_loader_get_entries(char ***ret) {
if (!end && entries[i] != 0)
continue;
+ /* Empty string at the end of variable? That's the trailer, we are done (i.e. we have a final
+ * NUL terminator). */
+ if (end && start == i)
+ break;
+
/* We reached the end of a string, let's decode it into UTF-8 */
decoded = utf16_to_utf8(entries + start, (i - start) * sizeof(char16_t));
if (!decoded)
@@ -125,7 +131,8 @@ int efi_loader_get_entries(char ***ret) {
} else
log_debug("Ignoring invalid loader entry '%s'.", decoded);
- /* We reached the end of the variable */
+ /* Exit the loop if we reached the end of the variable (i.e. we do not have a final NUL
+ * terminator) */
if (end)
break;