summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/strtol.c
diff options
context:
space:
mode:
authorjsing <jsing@openbsd.org>2012-11-18 04:13:39 +0000
committerjsing <jsing@openbsd.org>2012-11-18 04:13:39 +0000
commit9fd3a35ff4ddc94b3092414007045f6293a15038 (patch)
treef0129a6fdb09a62c6b28c36dcd0a7dc797f0176e /lib/libc/stdlib/strtol.c
parentAdd a regress test for strtol, which currently fails. (diff)
downloadwireguard-openbsd-9fd3a35ff4ddc94b3092414007045f6293a15038.tar.xz
wireguard-openbsd-9fd3a35ff4ddc94b3092414007045f6293a15038.zip
Ensure that the base provided to strtol(3) is between 2 and 36 inclusive,
or the special value of 0. ok deraadt@ otto@
Diffstat (limited to 'lib/libc/stdlib/strtol.c')
-rw-r--r--lib/libc/stdlib/strtol.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/libc/stdlib/strtol.c b/lib/libc/stdlib/strtol.c
index 5a244766db7..745bc4c2ce2 100644
--- a/lib/libc/stdlib/strtol.c
+++ b/lib/libc/stdlib/strtol.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: strtol.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */
+/* $OpenBSD: strtol.c,v 1.8 2012/11/18 04:13:39 jsing Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -49,6 +49,17 @@ strtol(const char *nptr, char **endptr, int base)
int neg, any, cutlim;
/*
+ * Ensure that base is between 2 and 36 inclusive, or the special
+ * value of 0.
+ */
+ if (base != 0 && (base < 2 || base > 36)) {
+ if (endptr != 0)
+ *endptr = nptr;
+ 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
* assume decimal; if base is already 16, allow 0x.