grok_infnan: Handle empty input

This public function dereferences its pointer parameter before checking
its validity.
This commit is contained in:
Karl Williamson 2026-01-14 12:19:13 -07:00 committed by Karl Williamson
parent cea46623dd
commit ed5117fa8b
3 changed files with 10 additions and 5 deletions

View File

@ -1434,8 +1434,8 @@ Adip |UV |grok_hex |NN const char *start \
|NN STRLEN *len_p \
|NN I32 *flags \
|NULLOK NV *result
Adp |int |grok_infnan |NN const char **sp \
|NN const char *send
Adp |int |grok_infnan |SPTR const char **sp \
|EPTRge const char *send
Adp |int |grok_number |NN const char *pv \
|STRLEN len \
|NULLOK UV *valuep

View File

@ -666,13 +666,18 @@ zero is returned, and C<*sp> will not move.
int
Perl_grok_infnan(pTHX_ const char** sp, const char* send)
{
PERL_ARGS_ASSERT_GROK_INFNAN;
const char* s = *sp;
if (UNLIKELY(s >= send)) {
return 0;
}
int flags = 0;
#if defined(NV_INF) || defined(NV_NAN)
bool odh = FALSE; /* one-dot-hash: 1.#INF */
PERL_ARGS_ASSERT_GROK_INFNAN;
if (*s == '+') {
s++; if (s == send) return 0;
}

2
proto.h generated
View File

@ -1259,7 +1259,7 @@ Perl_grok_bin_oct_hex(pTHX_ const char * const start, STRLEN *len_p, I32 *flags,
PERL_CALLCONV int
Perl_grok_infnan(pTHX_ const char **sp, const char *send);
#define PERL_ARGS_ASSERT_GROK_INFNAN \
assert(sp); assert(send)
assert(sp); assert(*sp); assert(send); assert(*sp <= send)
PERL_CALLCONV int
Perl_grok_number(pTHX_ const char *pv, STRLEN len, UV *valuep);