stub: Fix cmdline handling
authorJan Janssen <medhefgo@web.de>
Tue, 22 Nov 2022 16:42:38 +0000 (17:42 +0100)
committerJan Janssen <medhefgo@web.de>
Tue, 22 Nov 2022 16:42:38 +0000 (17:42 +0100)
commit927ebebe588970fa2dd082a0daaef246229f009b
treeacc489739b9137ac457f60814a2f3b48a27187c0
parent7444e10611671abac35be3ab9fe9697cd4c90d62
 stub: Fix cmdline handling

This fixes some bugs that could lead to garbage getting appended to the
command line passed to the kernel:
 1. The .cmdline section is not guaranteed to be NUL-terminated, but it
    was used as if it was.
 2. The conversion of the command line to ASCII that was passed to the
    stub ate the NUL at the end.
 3. LoadOptions is not guaranteed to be a NUL-terminated EFI string (it
    really should be and generally always is, though).

This also fixes the inconsistent mangling of the command line. If the
.cmdline section was used ASCII controls chars (new lines in particular)
would not be converted to spaces.

As part of this commit, we optimize conversion for the generic code
instead of the (deprecated) EFI handover protocol. Previously we would
convert to ASCII/UTF-8 and then back to EFI string for the (now) default
generic code path. Instead we now convert to EFI string and mangle that
back to ASCII in the EFI handover protocol path.
src/boot/efi/boot.c
src/boot/efi/linux.c
src/boot/efi/linux.h
src/boot/efi/linux_x86.c
src/boot/efi/stub.c
src/boot/efi/util.c
src/boot/efi/util.h