summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-07-25 05:55:22 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-07-25 05:55:22 +0000
commit8e2d0deb88c4c9539b5c963da8cfad2e8205298e (patch)
tree982a7304ff142b74df2c67ff0d3833640189d9db
parentd822aa29985acc2e5db6bc5b0be085526be5d618 (diff)
dir.c (ruby_brace_expand): RB_GC_GUARD safety
The lifetime of a String VALUE must match or exceed the lifetime of its R*_PTR result; otherwise the GC can while reclaim the VALUE while the R*_PTR result is in use. * dir.c (ruby_brace_expand): add var parameter for GC guard (ruby_brace_glob_with_enc): adjust call (file_s_fnmatch): ditto (push_glob): remove misplaced GC guard git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59416 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--dir.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/dir.c b/dir.c
index 3db196fef9..017f715080 100644
--- a/dir.c
+++ b/dir.c
@@ -2268,7 +2268,7 @@ push_pattern(const char *path, VALUE ary, void *enc)
static int
ruby_brace_expand(const char *str, int flags, ruby_glob_func *func, VALUE arg,
- rb_encoding *enc)
+ rb_encoding *enc, VALUE var)
{
const int escape = !(flags & FNM_NOESCAPE);
const char *p = str;
@@ -2313,7 +2313,7 @@ ruby_brace_expand(const char *str, int flags, ruby_glob_func *func, VALUE arg,
}
memcpy(buf+shift, t, p-t);
strlcpy(buf+shift+(p-t), rbrace+1, len-(shift+(p-t)));
- status = ruby_brace_expand(buf, flags, func, arg, enc);
+ status = ruby_brace_expand(buf, flags, func, arg, enc, var);
if (status) break;
}
GLOB_FREE(buf);
@@ -2322,6 +2322,7 @@ ruby_brace_expand(const char *str, int flags, ruby_glob_func *func, VALUE arg,
status = glob_call_func(func, s, arg, enc);
}
+ RB_GC_GUARD(var);
return status;
}
@@ -2349,7 +2350,7 @@ ruby_brace_glob_with_enc(const char *str, int flags, ruby_glob_func *func, VALUE
args.funcs.error = NULL;
args.value = arg;
args.flags = flags;
- return ruby_brace_expand(str, flags, glob_brace, (VALUE)&args, enc);
+ return ruby_brace_expand(str, flags, glob_brace, (VALUE)&args, enc, Qfalse);
}
int
@@ -2409,9 +2410,8 @@ push_glob(VALUE ary, VALUE str, VALUE base, int flags)
enc = rb_utf8_encoding();
#endif
- RB_GC_GUARD(str);
return ruby_brace_expand(RSTRING_PTR(str), flags,
- push_caller, (VALUE)&args, enc);
+ push_caller, (VALUE)&args, enc, str);
}
static VALUE
@@ -2905,7 +2905,7 @@ file_s_fnmatch(int argc, VALUE *argv, VALUE obj)
args.value = path;
args.flags = flags;
if (ruby_brace_expand(RSTRING_PTR(pattern), flags, fnmatch_brace,
- (VALUE)&args, rb_enc_get(pattern)) > 0)
+ (VALUE)&args, rb_enc_get(pattern), pattern) > 0)
return Qtrue;
}
else {