ruby-changes:65507
From: Nobuyoshi <ko1@a...>
Date: Fri, 19 Mar 2021 07:16:11 +0900 (JST)
Subject: [ruby-changes:65507] f748b911c9 (master): Fix infinite loop at illegal sequence [Bug #17729]
https://git.ruby-lang.org/ruby.git/commit/?id=f748b911c9 From f748b911c9157a0bb86f38280ddfba72a55049b6 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 18 Mar 2021 18:48:56 +0900 Subject: Fix infinite loop at illegal sequence [Bug #17729] As mblen returns -1 on failure, skip the first byte and try the succeeding bytes in that case. Close https://github.com/ruby/ruby/pull/4281 --- eval_intern.h | 11 ++++++++++- test/ruby/test_rubyoptions.rb | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/eval_intern.h b/eval_intern.h index 3448977..9fa9031 100644 --- a/eval_intern.h +++ b/eval_intern.h @@ -302,7 +302,16 @@ VALUE rb_ec_backtrace_location_ary(const rb_execution_context_t *ec, long lev, l https://github.com/ruby/ruby/blob/trunk/eval_intern.h#L302 #ifndef CharNext /* defined as CharNext[AW] on Windows. */ # ifdef HAVE_MBLEN -# define CharNext(p) ((p) + mblen((p), RUBY_MBCHAR_MAXSIZE)) +# define CharNext(p) rb_char_next(p) +static inline const char * +rb_char_next(const char *p) +{ + if (p) { + int len = mblen(p, RUBY_MBCHAR_MAXSIZE); + p += len > 0 ? len : 1; + } + return p; +} # else # define CharNext(p) ((p) + 1) # endif diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 0d42604..e26a24e 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -1089,6 +1089,11 @@ class TestRubyOptions < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L1089 end end + def test_rubylib_invalid_encoding + env = {"RUBYLIB"=>"\xFF", "LOCALE"=>"en_US.UTF-8", "LC_ALL"=>"en_US.UTF-8"} + assert_ruby_status([env, "-e;"]) + end + def test_null_script skip "#{IO::NULL} is not a character device" unless File.chardev?(IO::NULL) assert_in_out_err([IO::NULL], success: true) -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/