From 1b7ef41ee427b5551c3cbe60890a7d255bfd39bc Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 24 Apr 2020 16:01:23 +0000 Subject: [PATCH] fixed an array access problem by an out-of-range index in eval_indexed() --- hawk/lib/run.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hawk/lib/run.c b/hawk/lib/run.c index 13151700..fe22cd3e 100644 --- a/hawk/lib/run.c +++ b/hawk/lib/run.c @@ -6918,7 +6918,8 @@ static hawk_val_t* eval_indexed (hawk_rtx_t* rtx, hawk_nde_var_t* var) if (idx <= -1) return HAWK_NULL; arr = ((hawk_val_arr_t*)v)->arr; - return HAWK_ARR_SLOT(arr, idx)? ((hawk_val_t*)HAWK_ARR_DPTR(arr, idx)): ((hawk_val_t*)&hawk_val_nil); + /* return nil if the index is out of range or the element at the index is not set */ + return (idx < HAWK_ARR_SIZE(arr) && HAWK_ARR_SLOT(arr, idx))? ((hawk_val_t*)HAWK_ARR_DPTR(arr, idx)): hawk_val_nil; } default: