summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-15 16:05:04 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-15 16:05:04 +0000
commite117afcb70719022a362b0ae3433dddc1944def5 (patch)
treef8f1d9405d63249282888176efb06882746021e7 /string.c
parent13f618f1ed08ebe182c3bf2e4948fd3be2a2be3d (diff)
merge revision(s) 55054: [Backport #12390]
* string.c (rb_str_modify_expand): check integer overflow. [ruby-core:75592] [Bug #12390] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@55426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/string.c b/string.c
index 5625c2bd88..bc27b8cfdd 100644
--- a/string.c
+++ b/string.c
@@ -1820,6 +1820,9 @@ rb_str_modify_expand(VALUE str, long expand)
else if (expand > 0) {
long len = RSTRING_LEN(str);
long capa = len + expand;
+ if (expand >= LONG_MAX - len - termlen) {
+ rb_raise(rb_eArgError, "string size too big");
+ }
if (!STR_EMBED_P(str)) {
REALLOC_N(RSTRING(str)->as.heap.ptr, char, capa + termlen);
RSTRING(str)->as.heap.aux.capa = capa;