From 471e3a301624a86f08c86a643321c3656abbc9fd Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 11 Aug 2015 06:22:34 +0000 Subject: ruby.h: check integer overflow * include/ruby/ruby.h (ALLOCV_N): check integer overflow, as well as ruby_xmalloc2. pointed out by Paul . git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- gc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'gc.c') diff --git a/gc.c b/gc.c index a3af6fefbb..cd8682547a 100644 --- a/gc.c +++ b/gc.c @@ -7649,16 +7649,16 @@ ruby_xmalloc(size_t size) return objspace_xmalloc(&rb_objspace, size); } -static inline size_t -xmalloc2_size(size_t n, size_t size) +void +ruby_malloc_size_overflow(size_t count, size_t elsize) { - size_t len = size * n; - if (n != 0 && size != len / n) { - rb_raise(rb_eArgError, "malloc: possible integer overflow"); - } - return len; + rb_raise(rb_eArgError, + "malloc: possible integer overflow (%"PRIdSIZE"*%"PRIdSIZE")", + count, elsize); } +#define xmalloc2_size ruby_xmalloc2_size + void * ruby_xmalloc2(size_t n, size_t size) { -- cgit v1.2.3