From 2ec51ee0d506c90f3afba694e6c502ef3d52e4f8 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 20 Oct 2004 12:47:20 +0000 Subject: * 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 --- string.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 675af12088..9f0091721d 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; -- cgit v1.2.3