lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <AE90C24D6B3A694183C094C60CF0A2F6D8AEE6@saturn3.aculab.com>
Date:	Fri, 25 Nov 2011 17:34:21 -0000
From:	"David Laight" <David.Laight@...LAB.COM>
To:	"Stephen Hemminger" <shemminger@...tta.com>
Cc:	"Hagen Paul Pfeifer" <hagen@...u.net>, <netdev@...r.kernel.org>
Subject: RE: [PATCH iproute2 1/2] utils: add s32 parser

> From: Stephen Hemminger [mailto:shemminger@...tta.com] 
> "David Laight" <David.Laight@...LAB.COM> wrote:
> 
> > > +	res = strtoul(arg, &ptr, base);
> > > +	if (!ptr || ptr == arg || *ptr || res > INT32_MAX || res <  
> > INT32_MIN)
> > 
> > No need to check !ptr.
> 
> Also don't you want signed value?  Reading strtol() man page,
> the correct way is:
> 	errno = 0;
> 	res = strtol(arg, &ptr, base);
> 	if (ptr == arg || errno)
> 		return -1;
> 
> "RETURN VALUE
>        The strtol() function returns the result of the conversion,
unless  the
>        value  would  underflow  or overflow.  If an underflow occurs,
strtol()
>        returns LONG_MIN.  If an overflow occurs,  strtol() returns
LONG_MAX.
>        In  both  cases,  errno is set to ERANGE.  Precisely the same
holds for
>        strtoll()  (with  LLONG_MIN  and  LLONG_MAX  instead  of
LONG_MIN  and
>        LONG_MAX).

If you are that worried about numeric overflow (IIRC) you have
have to check the result for LONG_MIN/MAX (etc) before looking
at errno.

strtoul() is defined to support -ve values, and I think the
C rules for conversion between signed and unsigned ints
DTRT even for non 2's compliment systems.

Some of these bound checks are a waste of time.
The SUS doesn't require standard utilities to perform them.

	David


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ