diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-08-11 06:22:34 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-08-11 06:22:34 +0000 |
commit | 031574a33ddf9b6cb9f3bb8cee3334fb81333d54 (patch) | |
tree | feb1199979bf7b7ad2e54a4e3898a66420103e4a /gc.c | |
parent | 361b6fdf2d0e7ac932cc511e86e25065dfe8e4ed (diff) | |
download | ruby-031574a33ddf9b6cb9f3bb8cee3334fb81333d54.tar.gz |
ruby.h: check integer overflow
* include/ruby/ruby.h (ALLOCV_N): check integer overflow, as well
as ruby_xmalloc2. pointed out by Paul <pawlkt AT gmail.com>.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r-- | gc.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -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) { |