ruby-changes:68077
From: Nobuyoshi <ko1@a...>
Date: Wed, 22 Sep 2021 19:06:22 +0900 (JST)
Subject: [ruby-changes:68077] 7c0230b05d (master): Check the entire name as `ruby2_keywords_flag` [Bug #18184]
https://git.ruby-lang.org/ruby.git/commit/?id=7c0230b05d From 7c0230b05d0978958f89434c84ddd9c82419c1a5 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 22 Sep 2021 18:57:10 +0900 Subject: Check the entire name as `ruby2_keywords_flag` [Bug #18184] --- marshal.c | 2 +- test/ruby/test_marshal.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/marshal.c b/marshal.c index a817cf9..47b13bc 100644 --- a/marshal.c +++ b/marshal.c @@ -1424,7 +1424,7 @@ ruby2_keywords_flag_check(VALUE sym) https://github.com/ruby/ruby/blob/trunk/marshal.c#L1424 long l; RSTRING_GETMEM(sym, p, l); if (l <= 0) return 0; - if (name_equal(name_s_ruby2_keywords_flag, rb_strlen_lit(name_s_ruby2_keywords_flag), p, 1)) { + if (name_equal(name_s_ruby2_keywords_flag, rb_strlen_lit(name_s_ruby2_keywords_flag), p, l)) { return 1; } return 0; diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb index a0d9d96..619aaa6 100644 --- a/test/ruby/test_marshal.rb +++ b/test/ruby/test_marshal.rb @@ -806,8 +806,14 @@ class TestMarshal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_marshal.rb#L806 def test_marshal_with_ruby2_keywords_hash flagged_hash = ruby2_keywords_hash(key: 42) - hash = Marshal.load(Marshal.dump(flagged_hash)) + data = Marshal.dump(flagged_hash) + hash = Marshal.load(data) assert_equal(42, ruby2_keywords_test(*[hash])) + + hash2 = Marshal.load(data.sub!(/\x06K(?=T\z)/, "\x08KEY")) + assert_raise(ArgumentError, /\(given 1, expected 0\)/) { + ruby2_keywords_test(*[hash2]) + } end def exception_test -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/