string.c: check integer overflow using mrb_int_mul_overflow().

This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-03-02 15:34:28 +09:00
parent 0bf1ed9f2c
commit 51a3317c5b
+1 -3
View File
@@ -928,11 +928,9 @@ mrb_str_times(mrb_state *mrb, mrb_value self)
if (times < 0) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "negative argument");
}
if (times && MRB_SSIZE_MAX / times < RSTRING_LEN(self)) {
if (mrb_int_mul_overflow(RSTRING_LEN(self), times, &len)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "argument too big");
}
len = RSTRING_LEN(self)*times;
str2 = str_new(mrb, 0, len);
p = RSTR_PTR(str2);
if (len > 0) {