From 231db4657473247f753eff3dda736712538c9fd7 Mon Sep 17 00:00:00 2001 From: schwarze <> Date: Sat, 13 Sep 2014 20:10:12 +0000 Subject: 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@ --- src/lib/libc/stdlib/strtoll.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/lib/libc/stdlib/strtoll.c') diff --git a/src/lib/libc/stdlib/strtoll.c b/src/lib/libc/stdlib/strtoll.c index 4bcc5565be..cf82c8e1a6 100644 --- a/src/lib/libc/stdlib/strtoll.c +++ b/src/lib/libc/stdlib/strtoll.c @@ -1,5 +1,5 @@ -/* $OpenBSD: strtoll.c,v 1.7 2013/03/28 18:09:38 martynas Exp $ */ -/*- +/* $OpenBSD: strtoll.c,v 1.8 2014/09/13 20:10:12 schwarze Exp $ */ +/* * Copyright (c) 1992 The Regents of the University of California. * All rights reserved. * @@ -49,6 +49,17 @@ strtoll(const char *nptr, char **endptr, int base) int c; int neg, any, cutlim; + /* + * Ensure that base is between 2 and 36 inclusive, or the special + * value of 0. + */ + if (base < 0 || base == 1 || base > 36) { + if (endptr != 0) + *endptr = (char *)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 -- cgit v1.2.3-55-g6feb