ruby-changes:44951
From: nobu <ko1@a...>
Date: Thu, 8 Dec 2016 15:19:12 +0900 (JST)
Subject: [ruby-changes:44951] nobu:r57024 (trunk): vm.c: check type of hash to merge
nobu 2016-12-08 15:19:06 +0900 (Thu, 08 Dec 2016) New Revision: 57024 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57024 Log: vm.c: check type of hash to merge * vm.c (core_hash_merge): check the type of the target hash to merge. [ruby-core:78536] [Bug #13015] Modified files: trunk/test/ruby/test_keyword.rb trunk/vm.c Index: vm.c =================================================================== --- vm.c (revision 57023) +++ vm.c (revision 57024) @@ -2600,6 +2600,7 @@ core_hash_merge(VALUE hash, long argc, c https://github.com/ruby/ruby/blob/trunk/vm.c#L2600 { long i; + Check_Type(hash, T_HASH); VM_ASSERT(argc % 2 == 0); for (i=0; i<argc; i+=2) { rb_hash_aset(hash, argv[i], argv[i+1]); @@ -2620,7 +2621,7 @@ core_hash_from_ary(VALUE ary) https://github.com/ruby/ruby/blob/trunk/vm.c#L2621 { VALUE hash = rb_hash_new(); - RUBY_DTRACE_CREATE_HOOK(HASH, RARRAY_LEN(ary)); + RUBY_DTRACE_CREATE_HOOK(HASH, (Check_Type(ary, T_ARRAY), RARRAY_LEN(ary))); return core_hash_merge_ary(hash, ary); } @@ -2634,6 +2635,7 @@ m_core_hash_merge_ary(VALUE self, VALUE https://github.com/ruby/ruby/blob/trunk/vm.c#L2635 static VALUE core_hash_merge_ary(VALUE hash, VALUE ary) { + Check_Type(ary, T_ARRAY); core_hash_merge(hash, RARRAY_LEN(ary), RARRAY_CONST_PTR(ary)); return hash; } Index: test/ruby/test_keyword.rb =================================================================== --- test/ruby/test_keyword.rb (revision 57023) +++ test/ruby/test_keyword.rb (revision 57024) @@ -609,4 +609,24 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L609 assert_equal({x: 1, y: 2, **h}, obj.foo) } end + + def test_kwrest_overwritten + bug13015 = '[ruby-core:78536] [Bug #13015]' + + klass = EnvUtil.labeled_class("Parent") do + def initialize(d:) + end + end + + klass = EnvUtil.labeled_class("Child", klass) do + def initialize(d:, **h) + h = [2, 3] + super + end + end + + assert_raise_with_message(TypeError, /expected Hash/, bug13015) do + klass.new(d: 4) + end + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/