summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/strtoul.c
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2014-09-13 20:10:12 +0000
committerschwarze <schwarze@openbsd.org>2014-09-13 20:10:12 +0000
commitb252b5f6e1f8ed74b8fe0b3449eb72f4b9ca5f57 (patch)
tree5ae51484372ab07338f3115e93c87b33cf125245 /lib/libc/stdlib/strtoul.c
parentDon't say or imply that using ifconfig has anything to do with whether the (diff)
downloadwireguard-openbsd-b252b5f6e1f8ed74b8fe0b3449eb72f4b9ca5f57.tar.xz
wireguard-openbsd-b252b5f6e1f8ed74b8fe0b3449eb72f4b9ca5f57.zip
Make sure that the following functions return 0 and EINVAL as
required by the C standard when called with an invalid base: strtoll(), strtoimax(), strtoul(), strtoull(), and strtoumax(). Same behaviour for strtoq() and strtouq() even though not standardized. No functional change in strtol(), it was the only one already correct. While here, simplify the conditional expression for checking the base and sync whitespace and comments among the six files. ok millert@
Diffstat (limited to 'lib/libc/stdlib/strtoul.c')
-rw-r--r--lib/libc/stdlib/strtoul.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/libc/stdlib/strtoul.c b/lib/libc/stdlib/strtoul.c
index a236365d2f9..2aa41b76e4a 100644
--- a/lib/libc/stdlib/strtoul.c
+++ b/lib/libc/stdlib/strtoul.c
@@ -1,6 +1,6 @@
-/* $OpenBSD: strtoul.c,v 1.8 2013/04/17 17:40:35 tedu Exp $ */
+/* $OpenBSD: strtoul.c,v 1.9 2014/09/13 20:10:12 schwarze Exp $ */
/*
- * Copyright (c) 1990 Regents of the University of California.
+ * Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -50,6 +50,13 @@ strtoul(const char *nptr, char **endptr, int base)
/*
* See strtol for comments as to the logic used.
*/
+ if (base < 0 || base == 1 || base > 36) {
+ if (endptr != 0)
+ *endptr = (char *)nptr;
+ errno = EINVAL;
+ return 0;
+ }
+
s = nptr;
do {
c = (unsigned char) *s++;