summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-20 12:47:20 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-20 12:47:20 +0000
commit2ec51ee0d506c90f3afba694e6c502ef3d52e4f8 (patch)
treedb3928abc44090d749b6609bfb7ef49f2631a5c9 /string.c
parent959077c8e0ec27dfa72025a85c99a4acc26f6491 (diff)
* string.c (str_gsub): reentrant check. [ruby-dev:24432]
* backport all SEGV bug fixes from CVS HEAD. [ruby-dev:24536] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7090 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/string.c b/string.c
index 675af12..9f00917 100644
--- a/string.c
+++ b/string.c
@@ -2037,6 +2037,9 @@ str_gsub(argc, argv, str, bang)
if (iter) {
rb_match_busy(match);
val = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match)));
+ if (RSTRING(str)->ptr == buf) {
+ rb_raise(rb_eRuntimeError, "gsub reentered");
+ }
rb_backref_set(match);
}
else {
@@ -4297,7 +4300,7 @@ rb_str_crypt(str, salt)
{
extern char *crypt();
VALUE result;
- char *s, *cr;
+ char *s;
StringValue(salt);
if (RSTRING(salt)->len < 2)
@@ -4305,10 +4308,7 @@ rb_str_crypt(str, salt)
if (RSTRING(str)->ptr) s = RSTRING(str)->ptr;
else s = "";
- cr = crypt(s, RSTRING(salt)->ptr);
- s = ALLOCA_N(char, strlen(cr));
- strcpy(s, cr);
- result = rb_str_new2(s);
+ result = rb_str_new2(crypt(s, RSTRING(salt)->ptr));
OBJ_INFECT(result, str);
OBJ_INFECT(result, salt);
return result;