public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] man/man3/strtoul.3: BUGS: Signed numbers are not rejected
@ 2025-03-21 20:41 Alejandro Colomar
  2025-03-21 21:31 ` Bruno Haible
                   ` (3 more replies)
  0 siblings, 4 replies; 24+ messages in thread
From: Alejandro Colomar @ 2025-03-21 20:41 UTC (permalink / raw)
  To: linux-man, Bruno Haible; +Cc: Alejandro Colomar

[-- Attachment #1: Type: text/plain, Size: 1452 bytes --]

Reported-by: Bruno Haible <bruno@clisp.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---

Hi Bruno,

This is one of the patches I will apply after your report.  Please
review.  Thanks!


Cheers,
Alex


 man/man3/strtoul.3 | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/man/man3/strtoul.3 b/man/man3/strtoul.3
index 9eb260dae..62b9f65f6 100644
--- a/man/man3/strtoul.3
+++ b/man/man3/strtoul.3
@@ -204,11 +204,29 @@ .SH CAVEATS
 and then determine if an error occurred by checking whether
 .I errno
 has a nonzero value after the call.
-.P
-Negative values are considered valid input and are
-silently converted to the equivalent
-.I "unsigned long"
+.SH BUGS
+.SS Signed numbers
+Negative values
+are considered valid input and
+are silently converted to the equivalent
+.I unsigned long
 value.
+.P
+Users should reject signed numbers
+with a wrapper function.
+.IP
+.EX
+unsigned long
+strtoul_u(const char *restrict s, char **restrict endp, int base)
+{
+	while (isspace((unsigned char) *s))
+		s++;
+	if (!isxdigit((unsigned char) *s))
+		return 0;
+\&
+	return strtoul(s, endp, base);
+}
+.EE
 .SH EXAMPLES
 See the example on the
 .BR strtol (3)

Range-diff against v0:
-:  --------- > 1:  939641570 man/man3/strtoul.3: BUGS: Signed numbers are not rejected

base-commit: e921861a3d30cfc5f9263747a4e64a68e488288c
-- 
2.47.2


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2025-03-23 19:47 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-21 20:41 [PATCH v1] man/man3/strtoul.3: BUGS: Signed numbers are not rejected Alejandro Colomar
2025-03-21 21:31 ` Bruno Haible
2025-03-21 22:21   ` Alejandro Colomar
2025-03-21 22:18 ` [PATCH v2 0/2] strto[u]l(3) BUGS and CAVEATS Alejandro Colomar
2025-03-21 22:18   ` [PATCH v2 1/2] man/man3/strto[u]l.3: BUGS: Signed numbers and white space are not rejected Alejandro Colomar
2025-03-21 22:18   ` [PATCH v2 2/2] man/man3/strtol.3: CAVEATS: Clarify how to perform range checks Alejandro Colomar
2025-03-23  0:30 ` [PATCH v3 0/2] strto[u]l.3: BUGS and CAVEATS Alejandro Colomar
2025-03-23  0:30   ` [PATCH v3 1/2] man/man3/strto[u]l.3: BUGS: Signed numbers and white space are not rejected Alejandro Colomar
2025-03-23 10:27     ` Bruno Haible
2025-03-23 11:15       ` Alejandro Colomar
2025-03-23  0:30   ` [PATCH v3 2/2] man/man3/strtol.3: CAVEATS: Clarify how to perform range checks Alejandro Colomar
2025-03-23 11:43 ` [PATCH v4 0/2] strto[u]l.3: BUGS and CAVEATS Alejandro Colomar
2025-03-23 11:43   ` [PATCH v4 1/2] man/man3/strto[u]l.3: BUGS: Signed numbers and white space are not rejected Alejandro Colomar
2025-03-23 13:20     ` Bruno Haible
2025-03-23 14:00       ` Alejandro Colomar
2025-03-23 15:52         ` Bruno Haible
2025-03-23 16:55           ` Alejandro Colomar
2025-03-23 17:03             ` Alejandro Colomar
2025-03-23 17:11               ` Bruno Haible
2025-03-23 18:35                 ` Alejandro Colomar
2025-03-23 18:55           ` Alejandro Colomar
2025-03-23 19:26             ` Bruno Haible
2025-03-23 19:47               ` Alejandro Colomar
2025-03-23 11:43   ` [PATCH v4 2/2] man/man3/strtol.3: CAVEATS: Clarify how to perform range checks Alejandro Colomar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox