diff options
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -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'; } |