ruby-changes:47301
From: normal <ko1@a...>
Date: Tue, 25 Jul 2017 14:55:29 +0900 (JST)
Subject: [ruby-changes:47301] normal:r59416 (trunk): dir.c (ruby_brace_expand): RB_GC_GUARD safety
normal 2017-07-25 14:55:22 +0900 (Tue, 25 Jul 2017) New Revision: 59416 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59416 Log: 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 Modified files: trunk/dir.c Index: dir.c =================================================================== --- dir.c (revision 59415) +++ dir.c (revision 59416) @@ -2268,7 +2268,7 @@ push_pattern(const char *path, VALUE ary https://github.com/ruby/ruby/blob/trunk/dir.c#L2268 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 f https://github.com/ruby/ruby/blob/trunk/dir.c#L2313 } 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 f https://github.com/ruby/ruby/blob/trunk/dir.c#L2322 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 https://github.com/ruby/ruby/blob/trunk/dir.c#L2350 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 ba https://github.com/ruby/ruby/blob/trunk/dir.c#L2410 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, VA https://github.com/ruby/ruby/blob/trunk/dir.c#L2905 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 { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/