Re: [PATCH v1] xstrtol: 1 is not a valid base
Alejandro Colomar <[email protected]> Thu, 18 Jul 2024 21:53:43 +0200
| Newsgroups | dev.linux.lists.liba2i |
|---|---|
| Message-ID | <cye4ym2qhwgs6zmfdk72zxgxt7axgwruxvhhev4nfwtbg6nokm@n75ltval2dhf> |
--luq4sfc7e5vlmduj Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable From: Alejandro Colomar <[email protected]> To: Bruno Haible <[email protected]> Cc: [email protected], Paul Eggert <[email protected]>, =?utf-8?B?xJBvw6BuIFRy4bqnbiBDw7RuZw==?= Danh <[email protected]>, Eli Schwartz <[email protected]>, Sam James <[email protected]>, Serge Hallyn <[email protected]>, Iker Pedrosa <[email protected]>, "Andrew J. Hesford" <[email protected]>, Michael Vetter <[email protected]>, [email protected] Subject: Re: [PATCH v1] xstrtol: 1 is not a valid base References: <[email protected]> <2143892.otsE0voPBg@nimes> MIME-Version: 1.0 In-Reply-To: <2143892.otsE0voPBg@nimes> Hi Bruno, On Thu, Jul 18, 2024 at 08:06:07PM GMT, Bruno Haible wrote: > Alejandro Colomar wrote: > > If xstrtol() was being called with a base of 1, under some conditions it > > would invoke Undefined Behavior. >=20 > Yes, sure. A numeric base of 1 makes no sense, mathematically. >=20 > Thanks for the patch; applied. >=20 > Note that I disagree with the statement from > https://github.com/void-linux/void-packages/issues/51261#issuecomment-223= 7055195 : > > Yet he introduced that bug a decade ago >=20 > I wouldn't call it a bug. Gnulib does not document that passing a base of= 1 > to xstrtol is valid. While it's your api, borrowing the name of strtol(3) comes with implied semantics. I think it'd be common to assume that unless specifically documented, you behave like POSIX's strtol(3), which produces defined behavior for a base of 1. If not a bug, it was at least misleading. I don't claim that POSIX's choice was good; actually I think it makes little sense, and ISO C's choice of leaving it undefined was probably better. BTW, does gnulib have documentation for xstrtol()? I couldn't find it. And for MALLOC()? I'm interested in reading both. > It's known to everyone in the field that a base of 1 > makes no sense. So, what you saw here was a slightly incomplete input > validation check. >=20 > Thanks for the improvement. You're welcome! Have a lovely night! Alex > Bruno --=20 <https://www.alejandro-colomar.es/> --luq4sfc7e5vlmduj Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE6jqH8KTroDDkXfJAnowa+77/2zIFAmaZcscACgkQnowa+77/ 2zK+DA//Uw6A+Sb8xzFLtVeOaxSZ0Bn1xAUfXHOYYWuDnMcUvgfSyH9iYkeKLw7d LL4SnwJDbZoA/NpGciTKQyRYIfEbfGs8v9MwwRCwIIn1ZVj7BWWfzaI3q5hLAgxv fVkQcgTGSrhYH64T9C9gIEwrpy++vWWu2gxagio/HuQTp47ogPbz9QjmKoLudiHm Xdv1KaFua8qFkDlPq9/uxWvVwW0PVRW19jfCCY5ahkwGPsL0O4Ug4AM5gAdcju/N f5FOB3gR3XRQ6iLsgIWncDrZRm1Kmbxf4ZGFkIOKASr7P7W/2i2BG/KeCNrAYX8u 0TQgLsvnXXnu0R1IHfDW4QJdGTP6ocmPMQnbz0hWTZ9+wVUrOS1LatHDHg9MnIdL Vyhc+GqiJv/Bio1Zi9VQc23jpgj4bT5Eeiwcb4DP+IfF8iGg/3Sho9/SsEwldvxs BLlTifkH3Hobd37PhvoFAJM/azkqLKANbrvnSPKRnvKXx10pggTnyEd744YS1xrn bjWWPqrYCSywNNGYfB9O+wRoKVr43/bBDXBk4rC6BsUIvHCWZ6XgHJi8dEMgkGS+ RtQscvvHY3SRzfjQNx7TD480mvulSWRv6eZzTzqSbrPRBO+tbuKigaE1wYMSzP1h eWj/kPPL5rSvFdZTFm1TxhFMo7vDEWlGEkWQTkzoribuGpIx4rI= =A5/+ -----END PGP SIGNATURE----- --luq4sfc7e5vlmduj--