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>
}
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) {