Make string to number conversions fail on NUL char.

Contributed by Igor Munkin.
This commit is contained in:
Mike Pall
2020-02-13 17:39:51 +01:00
parent d85d6b3c1b
commit 0ad60ccbc3
4 changed files with 12 additions and 7 deletions

View File

@@ -169,7 +169,8 @@ static CPToken cp_number(CPState *cp)
TValue o;
do { cp_save(cp, cp->c); } while (lj_char_isident(cp_get(cp)));
cp_save(cp, '\0');
fmt = lj_strscan_scan((const uint8_t *)sbufB(&cp->sb), &o, STRSCAN_OPT_C);
fmt = lj_strscan_scan((const uint8_t *)sbufB(&cp->sb), sbuflen(&cp->sb)-1,
&o, STRSCAN_OPT_C);
if (fmt == STRSCAN_INT) cp->val.id = CTID_INT32;
else if (fmt == STRSCAN_U32) cp->val.id = CTID_UINT32;
else if (!(cp->mode & CPARSE_MODE_SKIP))