summaryrefslogtreecommitdiffstats
path: root/src/boot/efi/util.c
diff options
context:
space:
mode:
authorJia Zhang <zhang.jia@linux.alibaba.com>2022-12-25 05:29:11 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-12-26 11:12:23 +0100
commit486cf22c35780d9ed621b931f3534b3e6d659c17 (patch)
tree95a5196b693705886683ee79d1544490cd4498b3 /src/boot/efi/util.c
parentMerge pull request #25850 from poettering/switch-root-tweaks-minor (diff)
downloadsystemd-486cf22c35780d9ed621b931f3534b3e6d659c17.tar.xz
systemd-486cf22c35780d9ed621b931f3534b3e6d659c17.zip
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 <zhang.jia@linux.alibaba.com>
Diffstat (limited to '')
-rw-r--r--src/boot/efi/util.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c
index 0a6bb59dce..d1e1aa59ae 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) {