aboutsummaryrefslogtreecommitdiffstats
path: root/iseq.h
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2019-10-07 16:56:08 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2019-10-09 12:12:28 +0900
commit7e0ae1698d4db0baec858a46de8d1ae875360cf5 (patch)
tree646fbe720b13469679973060b8ab5299cf076236 /iseq.h
parenta220410be70264a0e4089c4d63a9c22dd688ca7c (diff)
downloadruby-7e0ae1698d4db0baec858a46de8d1ae875360cf5.tar.gz
avoid overflow in integer multiplication
This changeset basically replaces `ruby_xmalloc(x * y)` into `ruby_xmalloc2(x, y)`. Some convenient functions are also provided for instance `rb_xmalloc_mul_add(x, y, z)` which allocates x * y + z byes.
Diffstat (limited to 'iseq.h')
-rw-r--r--iseq.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/iseq.h b/iseq.h
index 5d24b81601..ef0dd7176d 100644
--- a/iseq.h
+++ b/iseq.h
@@ -26,7 +26,9 @@ extern const ID rb_iseq_shared_exc_local_tbl[];
static inline size_t
rb_call_info_kw_arg_bytes(int keyword_len)
{
- return sizeof(struct rb_call_info_kw_arg) + sizeof(VALUE) * (keyword_len - 1);
+ return rb_size_mul_add_or_raise(
+ keyword_len - 1, sizeof(VALUE), sizeof(struct rb_call_info_kw_arg),
+ rb_eRuntimeError);
}
#define ISEQ_COVERAGE(iseq) iseq->body->variable.coverage
@@ -67,7 +69,7 @@ static inline VALUE *
ISEQ_ORIGINAL_ISEQ_ALLOC(const rb_iseq_t *iseq, long size)
{
return iseq->body->variable.original_iseq =
- ruby_xmalloc2(size, sizeof(VALUE));
+ ALLOC_N(VALUE, size);
}
#define ISEQ_TRACE_EVENTS (RUBY_EVENT_LINE | \