Re: [PATCH] parse-options: fix segmentation fault when a required value is missing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jul 21, 2008 at 06:30:36PM +0000, Olivier Marin wrote:
> From: Olivier Marin <dkr@xxxxxxxxxxx>
> 
> p->argc represent the number of arguments that have not been parsed yet,
> _including_ the one we are currently parsing. If it is not greater than
> one then there is no more argument.
> 
> Signed-off-by: Olivier Marin <dkr@xxxxxxxxxxx>
Acked-by: Pierre Habouzit <madcoder@xxxxxxxxxx>

> ---
>  I hope this is the right fix.
> 
>  parse-options.c          |    2 +-
>  t/t0040-parse-options.sh |    7 +++++++
>  2 files changed, 8 insertions(+), 1 deletions(-)
> 
> diff --git a/parse-options.c b/parse-options.c
> index 987b015..71a7acf 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -22,7 +22,7 @@ static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,
>                 p->opt = NULL;
>         } else if (p->argc == 1 && (opt->flags & PARSE_OPT_LASTARG_DEFAULT)) {
>                 *arg = (const char *)opt->defval;
> -       } else if (p->argc) {
> +       } else if (p->argc > 1) {
>                 p->argc--;
>                 *arg = *++p->argv;
>         } else

  Gasp thanks, Junio pointed it to me already, and for some reason this
hasn't made it.

-- 
·O·  Pierre Habouzit
··O                                                madcoder@xxxxxxxxxx
OOO                                                http://www.madism.org

Attachment: pgpmbv4zbyYmi.pgp
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux