diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-08-12 09:41:39 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-08-12 09:41:39 +0000 |
commit | 7e97ab23f81b94b93dca9fec9ea8997c46a59e11 (patch) | |
tree | 96f83b7cab2bb3f047a335acec0c3ba99d31732c /string.c | |
parent | dfaaa55199638cd56edb05b22b11730920cb653d (diff) |
* string.c (rb_str_cat): fix buffer overflow.
* string.c (rb_str_append): nothing to append actually when `str2'
is empty.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -534,7 +534,7 @@ rb_str_cat(str, ptr, len) (FL_TEST(str, STR_NO_ORIG) && !FL_TEST(str, STR_ASSOC))) { return rb_str_buf_cat(str, ptr, len); } - REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len+1); + REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len+len+1); if (ptr) { memcpy(RSTRING(str)->ptr + RSTRING(str)->len, ptr, len); } @@ -594,8 +594,8 @@ rb_str_append(str, str2) StringValue(str2); rb_str_modify(str); - len = RSTRING(str)->len+RSTRING(str2)->len; - if (len > 0) { + if (RSTRING(str2)->len > 0) { + len = RSTRING(str)->len+RSTRING(str2)->len; if (RSTRING(str)->orig == 0 || (FL_TEST(str, STR_NO_ORIG) && !FL_TEST(str, STR_ASSOC))) { rb_str_buf_append(str, str2); |