Re: [PATCH] efi: pass NUL-inclusive sizes to ucs2_as_utf8()

From: Ard Biesheuvel

Date: Wed Sep 09 2026 - 07:53:52 EST


(drop x86@ from cc)

Hi Vincent,

On Tue, 8 Sep 2026, at 19:24, Vincent Mailhol wrote:
> An upcoming change will update ucs2_as_utf8() to expose a strscpy()
> style API where the size argument is the destination buffer size,
> including space for the final NUL terminator.
>
> Some EFI callers currently pass the exact number of UTF-8 payload bytes
> that they expect to copy and add the terminator themselves afterwards.
> Extend those sizes to include the final NUL terminator so the upcoming
> contract change does not truncate the converted output by one byte.
>
> Signed-off-by: Vincent Mailhol <mailhol@xxxxxxxxxx>
> ---
> Hi Ard,
>
> I saw that you pushed on efi-libstub-native-utf16 WIP branch [1] and did
> some testing, despite those changes not yet submitted for review.
>


Thanks for the review, but I am going to drop that change. I am also going
to drop the ucs2_strscpy() call from my series, and use memcpy() instead.
The guaranteed NUL terminator is not really needed for a printf() style
function, and it actually interferes with the precision handling.

Instead, I'm adding a ucs2_to_utf8() that takes a separate limit argument,
and putting efi_convert_cmdline() on its head entirely so we don't go
through the input character by character twice.

I'll have v2 out shortly, including your v3 with my tweaks on top.
Please take the time to review on list if you have the bandwidth. Thanks.