Re: [PATCH] libgloss, aarch64: Fix off-by-one in exception handler
"Richard Earnshaw (foss)" <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
On 24/11/2025 11:03, Alex Coplan wrote:
> There is a catch-all trap handler in the EL3 boot code found in
> libgloss/aarch64/cpu-init/rdimon-aem-el3.S. It makes a call to write
> which is equivalent to the following C code:
>
> write(STDERR_FILENO, "Terminated by exception.\n", 26);
>
> the problem is that 26 is the length of the string + 1, the correct
> length is 25:
>
> $ python3 -c 'print(len("Terminated by exception.\n"))'
> 25
>
> Therefore, as things stand, the trailing NUL byte is also written to
> stderr; this can be seen by inspecting the output of binaries built with
> e.g. -specs=aem-ve.specs before and after this patch is applied, as in
> the below:
>
> $ cat run_qemu.sh
> #!/bin/bash
> qemu-system-aarch64 -machine virt,secure=on -cpu neoverse-v1 -m 2g \
> -nographic -semihosting -device loader,file=$1,cpu-num=0
> $ ./run_qemu.sh before.exe 2>&1 | xxd
> 00000000: 5465 726d 696e 6174 6564 2062 7920 6578 Terminated by ex
> 00000010: 6365 7074 696f 6e2e 0a00 ception...
> $ ./run_qemu.sh after.exe 2>&1 | xxd
> 00000000: 5465 726d 696e 6174 6564 2062 7920 6578 Terminated by ex
> 00000010: 6365 7074 696f 6e2e 0a ception..
>
> This simple patch fixes the off-by-one error, passing the correct length
> to write in the exception handler.
> ---
>
> OK to commit? I'll need someone to commit on my behalf as I don't have
> write access.
>
Pushed.
Thanks
R.> Thanks,
> Alex
>
> ---
> libgloss/aarch64/cpu-init/rdimon-aem-el3.S | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>