]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: don't convert the trailing newline in mangle_stub_cmdline()
authorJia Zhang <zhang.jia@linux.alibaba.com>
Sun, 25 Dec 2022 04:29:11 +0000 (12:29 +0800)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 26 Dec 2022 10:12:23 +0000 (19:12 +0900)
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 <zhang.jia@linux.alibaba.com>
src/boot/efi/util.c

index 0a6bb59dced93e8aa388b6b89ea78cdd976d0b94..d1e1aa59aec672d89d027d82f7bdb92032656b35 100644 (file)
@@ -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) {