ruby-changes:58803
From: Jeremy <ko1@a...>
Date: Mon, 18 Nov 2019 08:00:55 +0900 (JST)
Subject: [ruby-changes:58803] ab42e5a486 (master): More fixes for $SAFE/taint post merging
https://git.ruby-lang.org/ruby.git/commit/?id=ab42e5a486 From ab42e5a486a5b27107296fa34056f03ac878e306 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Thu, 14 Nov 2019 18:54:13 -0800 Subject: More fixes for $SAFE/taint post merging diff --git a/compile.c b/compile.c index f439abb..7de6068 100644 --- a/compile.c +++ b/compile.c @@ -11469,8 +11469,6 @@ ibf_load_setup_bytes(struct ibf_load *load, VALUE loader_obj, const char *bytes, https://github.com/ruby/ruby/blob/trunk/compile.c#L11469 static void ibf_load_setup(struct ibf_load *load, VALUE loader_obj, VALUE str) { - rb_check_safe_obj(str); - if (RSTRING_LENINT(str) < (int)sizeof(struct ibf_header)) { rb_raise(rb_eRuntimeError, "broken binary format"); } diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index f6ef88e..0e76081 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -155,13 +155,15 @@ class TestBigDecimal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L155 end end - def test_BigDecimal_with_tainted_string - Thread.new { - $SAFE = 1 - BigDecimal('1'.taint) - }.join - ensure - $SAFE = 0 + if RUBY_VERSION < '2.7' + def test_BigDecimal_with_tainted_string + Thread.new { + $SAFE = 1 + BigDecimal('1'.taint) + }.join + ensure + $SAFE = 0 + end end def test_BigDecimal_with_exception_keyword diff --git a/test/fiddle/test_func.rb b/test/fiddle/test_func.rb index d170c59..ca89173 100644 --- a/test/fiddle/test_func.rb +++ b/test/fiddle/test_func.rb @@ -11,18 +11,6 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_func.rb#L11 assert_nil f.call(10) end - def test_syscall_with_tainted_string - f = Function.new(@libc['system'], [TYPE_VOIDP], TYPE_INT) - Thread.new { - $SAFE = 1 - assert_raise(SecurityError) do - f.call("uname -rs".dup.taint) - end - }.join - ensure - $SAFE = 0 - end - def test_sinf begin f = Function.new(@libm['sinf'], [TYPE_FLOAT], TYPE_FLOAT) diff --git a/test/fiddle/test_handle.rb b/test/fiddle/test_handle.rb index c0fac39..17f9c92 100644 --- a/test/fiddle/test_handle.rb +++ b/test/fiddle/test_handle.rb @@ -8,29 +8,6 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_handle.rb#L8 class TestHandle < TestCase include Fiddle - def test_safe_handle_open - Thread.new do - $SAFE = 1 - assert_raise(SecurityError) { - Fiddle::Handle.new(LIBC_SO.dup.taint) - } - end.join - ensure - $SAFE = 0 - end - - def test_safe_function_lookup - Thread.new do - h = Fiddle::Handle.new(LIBC_SO) - $SAFE = 1 - assert_raise(SecurityError) { - h["qsort".dup.taint] - } - end.join - ensure - $SAFE = 0 - end - def test_to_i handle = Fiddle::Handle.new(LIBC_SO) assert_kind_of Integer, handle.to_i diff --git a/test/readline/test_readline.rb b/test/readline/test_readline.rb index 4e82d46..e1c299c 100644 --- a/test/readline/test_readline.rb +++ b/test/readline/test_readline.rb @@ -43,19 +43,22 @@ module BasetestReadline https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb#L43 assert_equal("hello", Readline::HISTORY[0]) # Work around lack of SecurityError in Reline - # test mode with tainted prompt - return if kind_of?(TestRelineAsReadline) - - Thread.start { - $SAFE = 1 - assert_raise(SecurityError) do - replace_stdio(stdin.path, stdout.path) do - Readline.readline("> ".taint) - end + # test mode with tainted prompt. + # Also skip test on Ruby 2.7+, where $SAFE/taint is deprecated. + if RUBY_VERSION < '2.7' && !kind_of?(TestRelineAsReadline) + begin + Thread.start { + $SAFE = 1 + assert_raise(SecurityError) do + replace_stdio(stdin.path, stdout.path) do + Readline.readline("> ".taint) + end + end + }.join + ensure + $SAFE = 0 end - }.join - ensure - $SAFE = 0 + end end end @@ -96,7 +99,8 @@ module BasetestReadline https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb#L99 assert_equal(12, actual_point) assert_equal("first complete finish", Readline.line_buffer) assert_equal(Encoding.find("locale"), Readline.line_buffer.encoding) - assert_equal(true, Readline.line_buffer.tainted?) + assert_equal(true, Readline.line_buffer.tainted?) if RUBY_VERSION < '2.7' + assert_equal(22, Readline.point) stdin.rewind @@ -113,7 +117,8 @@ module BasetestReadline https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb#L117 assert_equal(12, actual_point) assert_equal("first complete finish", Readline.line_buffer) assert_equal(Encoding.find("locale"), Readline.line_buffer.encoding) - assert_equal(true, Readline.line_buffer.tainted?) + assert_equal(true, Readline.line_buffer.tainted?) if RUBY_VERSION < '2.7' + assert_equal(21, Readline.point) end end @@ -526,7 +531,7 @@ module BasetestReadline https://github.com/ruby/ruby/blob/trunk/test/readline/test_readline.rb#L531 end assert_equal('second\\ third', passed_text) - assert_equal('first completion', line) + assert_equal('first completion', line.chomp(' ')) ensure Readline.completer_quote_characters = saved_completer_quote_characters Readline.completer_word_break_characters = saved_completer_word_break_characters -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/