Re: [PATCH] Return EINVAL for illegal base in strtol

Corinna Vinschen <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
On Dec 16 13:55, Keith Packard wrote:
> Signed-off-by: Keith Packard <[email protected]>
> ---
>  newlib/libc/stdlib/strtol.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/newlib/libc/stdlib/strtol.c b/newlib/libc/stdlib/strtol.c
> index f7572b169..897890fe0 100644
> --- a/newlib/libc/stdlib/strtol.c
> +++ b/newlib/libc/stdlib/strtol.c
> @@ -140,6 +140,11 @@ _strtol_l (struct _reent *rptr, const char *__restrict nptr,
>  	register unsigned long cutoff;
>  	register int neg = 0, any, cutlim;
>  
> +	if (base < 0 || base == 1 || base > 36) {
> +		errno = EINVAL;
> +		return 0;
> +	}
> +
>  	/*
>  	 * Skip white space and pick up leading +/- sign if any.
>  	 * If base is 0, allow 0x for hex and 0 for octal, else
> @@ -193,9 +198,9 @@ _strtol_l (struct _reent *rptr, const char *__restrict nptr,
>  			break;
>  		if (c >= base)
>  			break;
> -               if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
> +		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) {
>  			any = -1;
> -		else {
> +		} else {
>  			any = 1;
>  			acc *= base;
>  			acc += c;
> -- 
> 2.24.0

Pushed.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAl34m0UACgkQ9TYGna5E
T6BXiw//ROvnmaefM946Pc8nwlWN3QjNJsVSLYY5IlGN0ibC/d0rmHplyuRnbf67
sZdBs+MOtFAmhPdl+6OdPc2Kolq3i2rURFhqTL9AvPhDLVcYGCpQgRM9F2cJa2CY
HuxJ1lxwU3bO/QAOBwhOZHx1Fe/agrxmMaQR1zYZ1s/SqRcc+ffzThj69AOuTS+j
mHz8xbUoWm0PwJTqfeyIZXWTZcTpwoBvYi41ivPvK0bWpK85MfmMbhKHcDBBPoT3
fwDG0xYqq2BMPbnjOGKN3LVUaO2KHF2fJ16n2cbNQu2Ic8ZlpQrKAjaqS/Pxc+Iy
BrzbhwRQO8Bfmaph/dol+Xx0CcnK7KdppD1NcYaDCZJiV2LzUYht9kD5YyoZO9WZ
EYYm9NpbNo8MjwGSJQRe3JZQozLeC80w+CoHmkbzNfHd0IsHiSwuTgwOtCLSgUge
V4RUudy9rAmpkL2E+MGJZy/IK0jSSPjN1GtUaaZXxy3kDCPJ+7D59MUsnitUO4sN
u7heio87l7s2un/FeG2Bw/gtQrxLMTqZkRoaR3zZDDk+Exv9yYFIRQL1Qj9BZcv3
AtQEEYm/icK5g/kkNYyXt8q0DbdfuxTtXrG3CrIPXfGs+0KvpDhkM35Y4/wTdgiP
ZFL9lOvLLOp6hOZSio+Jlu7Ey2u80Ls51+m0+k8qMmugTZTue1M=
=0o8/
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.