Questionable behavior of strtoi(3bsd) / strtou(3bsd)

Alejandro Colomar alx at kernel.org
Sun Jan 7 23:37:06 UTC 2024


On Sun, Jan 07, 2024 at 10:32:20PM +0100, Alejandro Colomar wrote:
...
> 	diff --git a/lib/libc/stdlib/strtonum.c b/lib/libc/stdlib/strtonum.c
> 	index 35ae6d2bda62..68623d0c499b 100644
> 	--- a/lib/libc/stdlib/strtonum.c
> 	+++ b/lib/libc/stdlib/strtonum.c
> 	@@ -62,6 +62,11 @@ strtonum(const char *nptr, long long minval, long long maxval,
> 			return rv;
> 		}
> 	 
> 	+       /* This code is correct, and would break if strtoi(3bsd) changed.
> 	+        * To prepare for it, we'd need to change the conditional to:
> 	+        *
> 	+        * (e == ERANGE && *end != '\0')

Oops, I should have written:

		   (e == ERANGE && *end == '\0')

> 	+        */
> 		if (e == ERANGE)
> 			*errstr = (rv == maxval ? "too large" : "too small");
> 		else
...
> 
> As you can see, there's only one place where changing strtoi(3bsd) would
> break, and it has an easy fix.  On the other hand, there are several
> bugs, due to precisely this strtoi(3bsd) bug, which would become fixed
> by fixing strtoi(3bsd).


-- 
<https://www.alejandro-colomar.es/>
Looking for a remote C programming job at the moment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/libbsd/attachments/20240108/3c2eabe2/attachment.sig>


More information about the libbsd mailing list