help-gengetopt
[Top][All Lists]
Advanced

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

Re: [help-gengetopt] Input validation


From: Ben Asselstine
Subject: Re: [help-gengetopt] Input validation
Date: Thu, 22 Dec 2005 08:38:35 -0500

The *end parameter to strto[u]l needs to be checked like this:

      {
        char *end;
        unsigned long int ms = strtoul (arg, &end, 10);
        if (end && *end == '\0')
          timeout = ms;
        else
          {
            argp_error (state,
                        "--timeout needs a numeric argument (milliseconds)");
            return EINVAL;
          }
      }

(yes it's an example from an argp-based program :-) )
Cheers,

Ben

On 12/22/05, Tiago Menezes <address@hidden> wrote:
> Dear all,
>
> I've recently started using gengetopt, a fantastic tool that has
> dramatically increased my productivity - thank you Lorenzo Bettini.
>
> I would like to raise an issue related to the validation of the
> command-line options (version 2.14: cygwin on Windows 2000, and on
> Linux).
>
> It is possible to type a text string as a value for an integer-type
> option. The parsed value will be 0, which may well be part of the
> acceptable input range. Reading cmdline.c, the offending code seems to
> be the function strtol(), inside cmdline_parser_internal(). Is this
> behaviour a true bug, or am I barking up the wrong tree (in which case
> I'd appreciate learning how to circumvent the problem from a seasoned
> programmer please).
>
> Many thanks and a Happy Christmas everyone,
> TM
>
>
> _______________________________________________
> Help-gengetopt mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-gengetopt
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]