[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH] libbb: ensure mode_string is NUL terminated
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2021-09-17 14:51:23
Message-ID: CAK1hOcOhWMnU7LHJ4zb3wc1FvPum-nNJ5u2WvFda9xh8MXVjFQ () mail ! gmail ! com
[Download RAW message or body]

Applied, thank you

On Fri, Sep 17, 2021 at 11:16 AM Ron Yorston <rmy@pobox.com> wrote:
>
> If the mode_string array is no longer static we can't rely on
> it being NUL terminated.
>
> function                                             old     new   delta
> bb_mode_string                                       145     156     +11
> ------------------------------------------------------------------------------
> (add/remove: 0/0 grow/shrink: 1/0 up/down: 11/0)               Total: 11 bytes
>
> Signed-off-by: Ron Yorston <rmy@pobox.com>
> ---
>  libbb/mode_string.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
>
> diff --git a/libbb/mode_string.c b/libbb/mode_string.c
> index 2b829016f..39a655d35 100644
> --- a/libbb/mode_string.c
> +++ b/libbb/mode_string.c
> @@ -66,10 +66,7 @@ char* FAST_FUNC bb_mode_string(char buf[12], mode_t mode)
>                 i += 4;
>         } while (i < 12);
>
> -       /* Note: We don't bother with nul termination because bss initialization
> -        * should have taken care of that for us.  If the user scribbled in buf
> -        * memory, they deserve whatever happens.  But we'll at least assert. */
> -       assert(buf[10] == 0);
> +       buf[10] = '\0';
>
>         return buf;
>  }
> @@ -107,10 +104,7 @@ char* FAST_FUNC bb_mode_string(char buf[12], mode_t mode)
>                 }
>         } while (i < 3);
>
> -       /* Note: We don't bother with nul termination because bss initialization
> -        * should have taken care of that for us.  If the user scribbled in buf
> -        * memory, they deserve whatever happens.  But we'll at least assert. */
> -       assert(buf[10] == 0);
> +       buf[10] = '\0';
>
>         return buf;
>  }
> --
> 2.31.1
>
> _______________________________________________
> busybox mailing list
> busybox@busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic