Add bouncs check to array index access.

This commit is contained in:
Stephen Chung 2020-02-23 14:09:40 +08:00
parent 829621a3d4
commit b2747b076e

View File

@ -513,8 +513,14 @@ impl Engine {
if let Some(arr_typed) =
(*val).downcast_mut() as Option<&mut Vec<Box<dyn Any>>>
{
arr_typed[i as usize] = rhs_val;
return Ok(Box::new(()));
return if i < 0 {
Err(EvalAltResult::ErrorArrayOutOfBounds(0, i))
} else if i as usize >= arr_typed.len() {
Err(EvalAltResult::ErrorArrayOutOfBounds(arr_typed.len(), i))
} else {
arr_typed[i as usize] = rhs_val;
Ok(Box::new(()))
};
} else {
return Err(EvalAltResult::ErrorIndexMismatch);
}