string.c: check integer overflow in mrb_str_aset().

This commit is contained in:
Yukihiro "Matz" Matsumoto
2021-09-09 19:12:36 +09:00
parent 5777e33c2a
commit 8a41d2b876
+4 -1
View File
@@ -1375,7 +1375,10 @@ mrb_str_aset(mrb_state *mrb, mrb_value str, mrb_value indx, mrb_value alen, mrb_
str_range_to_bytes(str, &beg, &len);
/* fall through */
case STR_BYTE_RANGE_CORRECTED:
str_replace_partial(mrb, str, beg, beg + len, replace);
if (mrb_int_add_overflow(beg, len, &len)) {
mrb_raise(mrb, E_RUNTIME_ERROR, "string index too big");
}
str_replace_partial(mrb, str, beg, len, replace);
}
}