Re: cmp(1): stricter checking for skip1 and skip2

2018-03-02 Thread Theo Buehler
On Fri, Mar 02, 2018 at 12:27:05PM +0100, Klemens Nanni wrote:
> On Thu, Mar 01, 2018 at 09:27:49PM -0600, Scott Cheloha wrote:
> > Hey,
> > 
> > This adds the more typical strtoll(3) checks we have elsewhere
> > in the tree to cmp(1).  Make sure we (a) got a number at all,
> > (b) that it doesn't have any dangling non-digits, (c) that it's
> > non-negative, and (d) that it didn't overflow.
> 
> > Index: usr.bin/cmp/cmp.c
> > ===
> > RCS file: /cvs/src/usr.bin/cmp/cmp.c,v
> > retrieving revision 1.16
> > diff -u -p -r1.16 cmp.c
> > --- usr.bin/cmp/cmp.c   28 Oct 2016 07:22:59 -  1.16
> > +++ usr.bin/cmp/cmp.c   2 Mar 2018 03:24:02 -
> 
> > @@ -141,6 +123,23 @@ main(int argc, char *argv[])
> > c_regular(fd1, file1, skip1, sb1.st_size,
> > fd2, file2, skip2, sb2.st_size);
> > return 0;
> > +}
> > +
> > +static off_t
> > +get_skip(const char *arg, const char *name)
> > +{
> > +off_t skip;
> > +char *ep;   
> > + 
> > +errno = 0;
> > +skip = strtoll(arg, , 0);
> > +if (ep == arg || *ep != '\0')
> > +fatalx("%s is invalid: %s", name, arg);
> > +if (skip < 0)
> > +fatalx("%s is too small: %s", name, arg);
> > +if (skip == LLONG_MAX && errno == ERANGE)
> > +fatalx("%s is too large: %s", name, arg);
> > +return skip;
> That's what strtonum(3) is for, why not using it?
> 

because strtonum only understands decimal. cmp -s takes octal and
hexadecimal as well



Re: cmp(1): stricter checking for skip1 and skip2

2018-03-02 Thread Klemens Nanni
On Thu, Mar 01, 2018 at 09:27:49PM -0600, Scott Cheloha wrote:
> Hey,
> 
> This adds the more typical strtoll(3) checks we have elsewhere
> in the tree to cmp(1).  Make sure we (a) got a number at all,
> (b) that it doesn't have any dangling non-digits, (c) that it's
> non-negative, and (d) that it didn't overflow.

> Index: usr.bin/cmp/cmp.c
> ===
> RCS file: /cvs/src/usr.bin/cmp/cmp.c,v
> retrieving revision 1.16
> diff -u -p -r1.16 cmp.c
> --- usr.bin/cmp/cmp.c 28 Oct 2016 07:22:59 -  1.16
> +++ usr.bin/cmp/cmp.c 2 Mar 2018 03:24:02 -

> @@ -141,6 +123,23 @@ main(int argc, char *argv[])
>   c_regular(fd1, file1, skip1, sb1.st_size,
>   fd2, file2, skip2, sb2.st_size);
>   return 0;
> +}
> +
> +static off_t
> +get_skip(const char *arg, const char *name)
> +{
> +off_t skip;
> +char *ep;   
> + 
> +errno = 0;
> +skip = strtoll(arg, , 0);
> +if (ep == arg || *ep != '\0')
> +fatalx("%s is invalid: %s", name, arg);
> +if (skip < 0)
> +fatalx("%s is too small: %s", name, arg);
> +if (skip == LLONG_MAX && errno == ERANGE)
> +fatalx("%s is too large: %s", name, arg);
> +return skip;
That's what strtonum(3) is for, why not using it?