1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

string.c (rb_str_set_len): pathological check

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-03-13 11:47:45 +00:00
parent b75f68ab8d
commit bd17e25588

View file

@ -2574,7 +2574,7 @@ rb_str_set_len(VALUE str, long len)
if (STR_SHARED_P(str)) { if (STR_SHARED_P(str)) {
rb_raise(rb_eRuntimeError, "can't set length of shared string"); rb_raise(rb_eRuntimeError, "can't set length of shared string");
} }
if (len > (capa = (long)str_capacity(str, termlen))) { if (len > (capa = (long)str_capacity(str, termlen)) || len < 0) {
rb_bug("probable buffer overflow: %ld for %ld", len, capa); rb_bug("probable buffer overflow: %ld for %ld", len, capa);
} }
STR_SET_LEN(str, len); STR_SET_LEN(str, len);