diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2019-10-07 16:56:08 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2019-10-09 12:12:28 +0900 |
commit | 7e0ae1698d4db0baec858a46de8d1ae875360cf5 (patch) | |
tree | 646fbe720b13469679973060b8ab5299cf076236 /iseq.h | |
parent | a220410be70264a0e4089c4d63a9c22dd688ca7c (diff) | |
download | ruby-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.h | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -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 | \ |