From c916010e870f340ebe9095805f530e419a729b2a Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Mon, 13 Jul 2020 14:08:18 +0200 Subject: [PATCH] Add a NULL check in strtol. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The spec says this is undefined behavior, but it will fix one more problem with #8297 Change-Id: Ibc15f306c92b05019de1050a9eb239ba57b1a91e Reviewed-on: https://review.haiku-os.org/c/haiku/+/3029 Reviewed-by: Axel Dörfler --- src/system/libroot/posix/glibc/stdlib/strtod.c | 6 ++++++ src/system/libroot/posix/glibc/stdlib/strtol.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/system/libroot/posix/glibc/stdlib/strtod.c b/src/system/libroot/posix/glibc/stdlib/strtod.c index b5d82692ab..e7c5ca52dd 100644 --- a/src/system/libroot/posix/glibc/stdlib/strtod.c +++ b/src/system/libroot/posix/glibc/stdlib/strtod.c @@ -494,6 +494,12 @@ INTERNAL (STRTOF) (nptr, endptr, group LOCALE_PARAM) struct locale_data *current = loc->__locales[LC_NUMERIC]; #endif + if (nptr == NULL) + { + __set_errno (EINVAL); + return NAN; + } + if (group) { grouping = _NL_CURRENT (LC_NUMERIC, GROUPING); diff --git a/src/system/libroot/posix/glibc/stdlib/strtol.c b/src/system/libroot/posix/glibc/stdlib/strtol.c index eb8602f637..c4da0073a0 100644 --- a/src/system/libroot/posix/glibc/stdlib/strtol.c +++ b/src/system/libroot/posix/glibc/stdlib/strtol.c @@ -288,7 +288,7 @@ INTERNAL (strtol) (nptr, endptr, base, group LOCALE_PARAM) grouping = NULL; #endif - if (base < 0 || base == 1 || base > 36) + if (base < 0 || base == 1 || base > 36 || nptr == NULL) { __set_errno (EINVAL); return 0;