added fuzzer and fixed a couple of bugs found by it

This commit is contained in:
cozis
2022-04-25 00:56:35 +02:00
parent f89d0ce6d2
commit 131fc7f009
5 changed files with 50 additions and 2 deletions
+9 -1
View File
@@ -939,6 +939,8 @@ static xj_value *parse_number(context_t *ctx)
return NULL;
}
int exponent_start = ctx->i;
_Bool negative_exponent = 0;
if(ctx->str[ctx->i] == '+' || ctx->str[ctx->i] == '-')
{
@@ -956,7 +958,7 @@ static xj_value *parse_number(context_t *ctx)
if(!isdigit(ctx->str[ctx->i]))
{
xj_report(ctx->error, ctx->str, ctx->i, "Expected digit as exponent");
xj_preport(ctx->error, ctx->str, ctx->i, "Expected digit as exponent");
return NULL;
}
@@ -968,6 +970,12 @@ static xj_value *parse_number(context_t *ctx)
ctx->i += 1;
}
if(exponent > 6)
{
xj_preport(ctx->error, ctx->str, exponent_start, "Exponent is too big");
return NULL;
}
coeff = 1;
for(int j = 0; j < exponent; j += 1)
coeff *= 10;