summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-10 06:58:57 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-10 06:58:57 +0000
commit23bc28e2df5b9de81529bc07ccd4aebd8a5f9e3e (patch)
tree36e67dfcfb641f641b00287c00555e2adb0dcf7b /string.c
parent7a25e90ee5174d975c44ed232258ff5c41a54a18 (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_2@55352 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 3edc3f55c3..e8a7a36412 100644
--- a/string.c
+++ b/string.c
@@ -1635,6 +1635,9 @@ rb_str_modify_expand(VALUE str, long expand)
long len = RSTRING_LEN(str);
long capa = len + expand;
int termlen = TERM_LEN(str);
+ 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;