ruby-changes:45270
From: nagachika <ko1@a...>
Date: Tue, 17 Jan 2017 04:08:12 +0900 (JST)
Subject: [ruby-changes:45270] nagachika:r57343 (ruby_2_3): merge revision(s) 56894: [Backport #12974]
nagachika 2017-01-17 04:08:08 +0900 (Tue, 17 Jan 2017) New Revision: 57343 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57343 Log: merge revision(s) 56894: [Backport #12974] marshal.c: fix infinite recursion * marshal.c (check_userdump_arg): marshal_dump should not return an instance of the same class, otherwise it causes infinite recursion. [ruby-core:78289] [Bug #12974] Modified directories: branches/ruby_2_3/ Modified files: branches/ruby_2_3/marshal.c branches/ruby_2_3/test/ruby/test_marshal.rb branches/ruby_2_3/version.h Index: ruby_2_3/version.h =================================================================== --- ruby_2_3/version.h (revision 57342) +++ ruby_2_3/version.h (revision 57343) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1 #define RUBY_VERSION "2.3.3" #define RUBY_RELEASE_DATE "2017-01-17" -#define RUBY_PATCHLEVEL 227 +#define RUBY_PATCHLEVEL 228 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 1 Index: ruby_2_3/marshal.c =================================================================== --- ruby_2_3/marshal.c (revision 57342) +++ ruby_2_3/marshal.c (revision 57343) @@ -178,8 +178,22 @@ check_dump_arg(VALUE ret, struct dump_ar https://github.com/ruby/ruby/blob/trunk/ruby_2_3/marshal.c#L178 } return ret; } + +static VALUE +check_userdump_arg(VALUE obj, ID sym, int argc, const VALUE *argv, + struct dump_arg *arg, const char *name) +{ + VALUE ret = rb_funcallv(obj, sym, argc, argv); + VALUE klass = CLASS_OF(obj); + if (CLASS_OF(ret) == klass) { + rb_raise(rb_eRuntimeError, "%"PRIsVALUE"#%s returned same class instance", + klass, name); + } + return check_dump_arg(ret, arg, name); +} + #define dump_funcall(arg, obj, sym, argc, argv) \ - check_dump_arg(rb_funcallv(obj, sym, argc, argv), arg, name_##sym) + check_userdump_arg(obj, sym, argc, argv, arg, name_##sym) #define dump_check_funcall(arg, obj, sym, argc, argv) \ check_dump_arg(rb_check_funcall(obj, sym, argc, argv), arg, name_##sym) Index: ruby_2_3/test/ruby/test_marshal.rb =================================================================== --- ruby_2_3/test/ruby/test_marshal.rb (revision 57342) +++ ruby_2_3/test/ruby/test_marshal.rb (revision 57343) @@ -736,4 +736,16 @@ class TestMarshal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_marshal.rb#L736 end RUBY end + + class Bug12974 + def marshal_dump + dup + end + end + + def test_marshal_dump_recursion + assert_raise_with_message(RuntimeError, /same class instance/) do + Marshal.dump(Bug12974.new) + end + end end Property changes on: ruby_2_3 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r56894 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/