Add a NULL check in strtol.

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 <[email protected]>
This commit is contained in:
Adrien Destugues
2020-07-13 19:34:09 +00:00
committed by Axel Dörfler
parent 15ba64aaa3
commit c916010e87
2 changed files with 7 additions and 1 deletions
@@ -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);
@@ -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;