From c212aadd9a791a789adcf7f5b9989f21942518fb Mon Sep 17 00:00:00 2001 From: millert <> Date: Thu, 6 Jul 2017 16:23:11 +0000 Subject: [PATCH] The 0x (or 0X) prefix in base 16 is optional so only skip over the prefix if the character following it is a valid hex char. The C99 standard is clear that given the string "0xy" zero should be returned and endptr set to point to the "x". OK deraadt@ espie@ --- src/lib/libc/stdlib/strtoimax.c | 6 +++--- src/lib/libc/stdlib/strtol.c | 6 +++--- src/lib/libc/stdlib/strtoll.c | 6 +++--- src/lib/libc/stdlib/strtoul.c | 6 +++--- src/lib/libc/stdlib/strtoull.c | 6 +++--- src/lib/libc/stdlib/strtoumax.c | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/lib/libc/stdlib/strtoimax.c b/src/lib/libc/stdlib/strtoimax.c index 52403a72..74e35562 100644 --- a/src/lib/libc/stdlib/strtoimax.c +++ b/src/lib/libc/stdlib/strtoimax.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strtoimax.c,v 1.3 2015/09/12 16:23:14 guenther Exp $ */ +/* $OpenBSD: strtoimax.c,v 1.4 2017/07/06 16:23:11 millert Exp $ */ /* * Copyright (c) 1992 The Regents of the University of California. * All rights reserved. @@ -74,8 +74,8 @@ strtoimax(const char *nptr, char **endptr, int base) if (c == '+') c = *s++; } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { + if ((base == 0 || base == 16) && c == '0' && + (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) { c = s[1]; s += 2; base = 16; diff --git a/src/lib/libc/stdlib/strtol.c b/src/lib/libc/stdlib/strtol.c index 49465e28..599d2355 100644 --- a/src/lib/libc/stdlib/strtol.c +++ b/src/lib/libc/stdlib/strtol.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strtol.c,v 1.11 2015/09/13 08:31:48 guenther Exp $ */ +/* $OpenBSD: strtol.c,v 1.12 2017/07/06 16:23:11 millert Exp $ */ /* * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -75,8 +75,8 @@ strtol(const char *nptr, char **endptr, int base) if (c == '+') c = *s++; } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { + if ((base == 0 || base == 16) && c == '0' && + (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) { c = s[1]; s += 2; base = 16; diff --git a/src/lib/libc/stdlib/strtoll.c b/src/lib/libc/stdlib/strtoll.c index 0ba51da7..d21a249a 100644 --- a/src/lib/libc/stdlib/strtoll.c +++ b/src/lib/libc/stdlib/strtoll.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strtoll.c,v 1.9 2015/09/13 08:31:48 guenther Exp $ */ +/* $OpenBSD: strtoll.c,v 1.10 2017/07/06 16:23:11 millert Exp $ */ /* * Copyright (c) 1992 The Regents of the University of California. * All rights reserved. @@ -77,8 +77,8 @@ strtoll(const char *nptr, char **endptr, int base) if (c == '+') c = *s++; } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { + if ((base == 0 || base == 16) && c == '0' && + (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) { c = s[1]; s += 2; base = 16; diff --git a/src/lib/libc/stdlib/strtoul.c b/src/lib/libc/stdlib/strtoul.c index 98e8abcb..6667bea8 100644 --- a/src/lib/libc/stdlib/strtoul.c +++ b/src/lib/libc/stdlib/strtoul.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strtoul.c,v 1.10 2015/09/13 08:31:48 guenther Exp $ */ +/* $OpenBSD: strtoul.c,v 1.11 2017/07/06 16:23:11 millert Exp $ */ /* * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -69,8 +69,8 @@ strtoul(const char *nptr, char **endptr, int base) if (c == '+') c = *s++; } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { + if ((base == 0 || base == 16) && c == '0' && + (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) { c = s[1]; s += 2; base = 16; diff --git a/src/lib/libc/stdlib/strtoull.c b/src/lib/libc/stdlib/strtoull.c index a5d07de6..d7733e40 100644 --- a/src/lib/libc/stdlib/strtoull.c +++ b/src/lib/libc/stdlib/strtoull.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strtoull.c,v 1.8 2015/09/13 08:31:48 guenther Exp $ */ +/* $OpenBSD: strtoull.c,v 1.9 2017/07/06 16:23:11 millert Exp $ */ /* * Copyright (c) 1992 The Regents of the University of California. * All rights reserved. @@ -71,8 +71,8 @@ strtoull(const char *nptr, char **endptr, int base) if (c == '+') c = *s++; } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { + if ((base == 0 || base == 16) && c == '0' && + (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) { c = s[1]; s += 2; base = 16; diff --git a/src/lib/libc/stdlib/strtoumax.c b/src/lib/libc/stdlib/strtoumax.c index 4c5e3349..348184c1 100644 --- a/src/lib/libc/stdlib/strtoumax.c +++ b/src/lib/libc/stdlib/strtoumax.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strtoumax.c,v 1.3 2015/09/12 16:23:14 guenther Exp $ */ +/* $OpenBSD: strtoumax.c,v 1.4 2017/07/06 16:23:11 millert Exp $ */ /* * Copyright (c) 1992 The Regents of the University of California. * All rights reserved. @@ -68,8 +68,8 @@ strtoumax(const char *nptr, char **endptr, int base) if (c == '+') c = *s++; } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { + if ((base == 0 || base == 16) && c == '0' && + (*s == 'x' || *s == 'X') && isxdigit((unsigned char)s[1])) { c = s[1]; s += 2; base = 16;