summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-05 11:00:18 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-05 11:00:18 +0000
commitb80ddbf461a9a215513d6bbd78bab7185a927a31 (patch)
treee2427c009dd63a9b8deab45d7d8dd8b9572101b7 /string.c
parent50b50499210bb52d1bbae6b65009f058426d2d1a (diff)
* string.c (rb_str_set_len): bail out when buffer overflowed
probably. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28871 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/string.c b/string.c
index cb371c2662..0aa2e6c52c 100644
--- a/string.c
+++ b/string.c
@@ -1693,10 +1693,15 @@ rb_str_unlocktmp(VALUE str)
void
rb_str_set_len(VALUE str, long len)
{
+ long capa;
+
str_modifiable(str);
if (STR_SHARED_P(str)) {
rb_raise(rb_eRuntimeError, "can't set length of shared string");
}
+ if (len > (capa = (long)rb_str_capacity(str))) {
+ rb_bug("probable buffer overflow: %ld for %ld", len, capa);
+ }
STR_SET_LEN(str, len);
RSTRING_PTR(str)[len] = '\0';
}