On Thu, Dec 16, 2021 at 12:26 PM Ron Yorston <[email protected]> wrote:
> The '%' character in a format specification may be followed by
> one or more flags from the list "+- #0".  BusyBox printf didn't
> support the '0' flag or allow multiple flags to be provided.
> As a result the formats '%0*d' and '%0 d' were considered to be
> invalid.
>
> The lack of support for '0' was pointed out by Andrew Snyder on the
> musl mailing list:
>
>    https://www.openwall.com/lists/musl/2021/12/14/2
>
> function                                             old     new   delta
> printf_main                                          860     891     +31
> .rodata                                            99281   99282      +1
> ------------------------------------------------------------------------------
> (add/remove: 0/0 grow/shrink: 2/0 up/down: 32/0)               Total: 32 bytes
>
> Signed-off-by: Ron Yorston <[email protected]>
> ---
>  coreutils/printf.c     |  8 +++++---
>  testsuite/printf.tests | 10 ++++++++++
>  2 files changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/coreutils/printf.c b/coreutils/printf.c
> index dd94c8ade..e5cf5f942 100644
> --- a/coreutils/printf.c
> +++ b/coreutils/printf.c
> @@ -313,9 +313,11 @@ static char **print_formatted(char *f, char **argv, int 
> *conv_err)
>                                 }
>                                 break;
>                         }
> -                       if (*f && strchr("-+ #", *f)) {
> -                               ++f;
> -                               ++direc_length;
> +                       if (*f) {
> +                               while (strchr("-+ #0", *f)) {
> +                                       ++f;
> +                                       ++direc_length;
> +                               }

This can walk off the end of "f", doesn't it?
[strchr("anything", '\0') is not NULL]
I propose

                        while (*f && strchr("-+ #0", *f)) {
                                ++f;
                                ++direc_length;
                        }
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to