Hi,

> From: Maks Mishin <[email protected]>
>
> Signed-off-by: Maks Mishin <[email protected]>
> ---
>  coreutils/od_bloaty.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
> index 5b5e56a..d5b8999 100644
> --- a/coreutils/od_bloaty.c
> +++ b/coreutils/od_bloaty.c
> @@ -1233,8 +1233,10 @@ int od_main(int argc UNUSED_PARAM, char **argv)
>                                 "'%c' (must be [doxn])", str_A[0]);
>                 pos = p - doxn;
>                 if (pos == 3) G.format_address = format_address_none;
> -               address_base_char = doxn_address_base_char[pos];
> -               address_pad_len_char = doxn_address_pad_len_char[pos];
> +               if (pos < 3) {
> +                       address_base_char = doxn_address_base_char[pos];
> +                       address_pad_len_char = doxn_address_pad_len_char[pos];
> +               }
>         }
>         if (opt & OPT_N) {
>                 max_bytes_to_format = xstrtooff_sfx(str_N, 0, bkm_suffixes);
> --

The only way that pos is not in a valid range (0..2) is because user
passed '\0' as argument. In that case, the argument is invalid, so the
same error should be thrown, not ignore it without notice.

How about something like this?

        p = strchr(doxn, str_A[0]);
-        if (!p)
+        if (!p || !*p)
            bb_error_msg_and_die("bad output address radix "
                "'%c' (must be [doxn])", str_A[0]);

Or maybe using strchrnul(3) and only check for (!*p) instead is smaller?

Cheers,

Xabier Oneca_,,_
_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to