[PATCH] nvmecontrol: Fix shortopts allocation
Warner Losh
imp at bsdimp.com
Wed Sep 11 13:30:25 UTC 2019
On Wed, Sep 11, 2019 at 2:28 AM Sebastian Huber <
sebastian.huber at embedded-brains.de> wrote:
> Account for potential ':' in the short options string.
> ---
> sbin/nvmecontrol/comnd.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sbin/nvmecontrol/comnd.c b/sbin/nvmecontrol/comnd.c
> index d8d97ad11b5..a91969ff766 100644
> --- a/sbin/nvmecontrol/comnd.c
> +++ b/sbin/nvmecontrol/comnd.c
> @@ -189,7 +189,7 @@ arg_parse(int argc, char * const * argv, const struct
> cmd *f)
> lopts = malloc((n + 2) * sizeof(struct option));
> if (lopts == NULL)
> err(1, "option memory");
> - p = shortopts = malloc((n + 3) * sizeof(char));
> + p = shortopts = malloc((2 * n + 2) * sizeof(char));
>
I'll apply, but I still think this needs to be + 3 to account for the NUL
at the end (even though we kinda know that the 2 options we're adding don't
have :.
> if (shortopts == NULL)
> err(1, "shortopts memory");
> idx = 0;
> --
> 2.16.4
>
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
>
More information about the freebsd-hackers
mailing list