diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-01-16 19:08:08 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-01-16 19:08:08 +0000 |
commit | c6250c600e2ccae73392415e383fd914c124600c (patch) | |
tree | e171619decc4b89b7d55bba6fbc1c060a891f789 | |
parent | 3032b62d5471e7acefc96f13de24c2ffba33ac19 (diff) |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@57343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | marshal.c | 16 | ||||
-rw-r--r-- | test/ruby/test_marshal.rb | 12 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 28 insertions, 2 deletions
@@ -178,8 +178,22 @@ check_dump_arg(VALUE ret, struct dump_arg *arg, const char *name) } 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) diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb index e2e321bb41..6ac5c29991 100644 --- a/test/ruby/test_marshal.rb +++ b/test/ruby/test_marshal.rb @@ -736,4 +736,16 @@ class TestMarshal < Test::Unit::TestCase 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 @@ -1,6 +1,6 @@ #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 |