[PATCH] lib: sbi: Handle length of extension name string exceed buffer size error

Anup Patel anup at brainfault.org
Sun Apr 20 21:23:27 PDT 2025


On Fri, Mar 21, 2025 at 6:11 AM Jimmy Ho <jimmy.ho at sifive.com> wrote:
>
> print error message and turncat the string when length
> of extension name string exceed buffer size
>
> Signed-off-by: Jimmy Ho <jimmy.ho at sifive.com>
> Reviewd-by: Nick Hu <nick.hu at sifive.com>
> Reviewd-by: Zong Li <zong.li at sifive.com>

s/Reviewd-by/Reviewed-by/

I have corrected this at the time of merging this patch.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

> ---
>  lib/sbi/sbi_hart.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
> index 15070021..0acf6063 100644
> --- a/lib/sbi/sbi_hart.c
> +++ b/lib/sbi/sbi_hart.c
> @@ -743,6 +743,10 @@ void sbi_hart_get_extensions_str(struct sbi_scratch *scratch,
>         sbi_memset(extensions_str, 0, nestr);
>
>         for_each_set_bit(ext, hfeatures->extensions, SBI_HART_EXT_MAX) {
> +               if (offset + sbi_strlen(sbi_hart_ext[ext].name) + 1 > nestr) {
> +                       sbi_printf("%s:extension name is longer than buffer (error)\n", __func__);
> +                       break;
> +               }
>                 sbi_snprintf(extensions_str + offset,
>                                  nestr - offset,
>                                  "%s,", sbi_hart_ext[ext].name);
> --
> 2.43.2
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi



More information about the opensbi mailing list