From: Jia Zhang Date: Sun, 25 Dec 2022 04:29:11 +0000 (+0800) Subject: boot: don't convert the trailing newline in mangle_stub_cmdline() X-Git-Tag: v253-rc1~212 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=486cf22c35780d9ed621b931f3534b3e6d659c17;p=thirdparty%2Fsystemd.git boot: don't convert the trailing newline in mangle_stub_cmdline() It is pretty convenient to add .cmdline using /proc/cmdline like this: --add-section .cmdline=/proc/cmdline --change-section-vma .cmdline=0x25000 However, it always returns a trailing newline, and stub will convert it to a whitespace by mangle_stub_cmdline() in next boot. Thus the resulting /proc/cmdline would contain a trailing whitespace. When /proc/cmdline is used to generate .cmdline again, the resulting UKI is mangled. To address this kind of inconvenience, mangle_stub_cmdline() should skip converting the trailing newline, and try to chomp all the trailing whitespaces. Signed-off-by: Jia Zhang --- diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index 0a6bb59dced..d1e1aa59aec 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -275,10 +275,22 @@ char16_t *xstr8_to_path(const char *str8) { } void mangle_stub_cmdline(char16_t *cmdline) { + char16_t *p = cmdline; + for (; *cmdline != '\0'; cmdline++) /* Convert ASCII control characters to spaces. */ if (*cmdline <= 0x1F) *cmdline = ' '; + + /* chomp the trailing whitespaces */ + while (cmdline != p) { + --cmdline; + + if (*cmdline != ' ') + break; + + *cmdline = '\0'; + } } EFI_STATUS file_read(EFI_FILE *dir, const char16_t *name, UINTN off, UINTN size, char **ret, UINTN *ret_size) {