summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNARUSE, Yui <[email protected]>2021-04-02 12:27:26 +0900
committerNARUSE, Yui <[email protected]>2021-04-02 12:27:26 +0900
commit1a47de64f44da6d4339ba8b2c5220eeaba82954c (patch)
tree9a6edc691c4b97cedcc9ad2231b02d70098591d8
parentd1cec0bca588266b9af1d55e592016c45ee68fbb (diff)
merge revision(s) f748b911c9157a0bb86f38280ddfba72a55049b6: [Backport #17729]
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(-)
-rw-r--r--eval_intern.h11
-rw-r--r--test/ruby/test_rubyoptions.rb5
-rw-r--r--version.h2
3 files changed, 16 insertions, 2 deletions
diff --git a/eval_intern.h b/eval_intern.h
index 34489777a2..9fa9031189 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
#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 b7831948f0..0d0f4b4d7e 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -1075,6 +1075,11 @@ class TestRubyOptions < Test::Unit::TestCase
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)
diff --git a/version.h b/version.h
index 5f07f2c35e..15531eb1ce 100644
--- a/version.h
+++ b/version.h
@@ -12,7 +12,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 0
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 58
+#define RUBY_PATCHLEVEL 59
#define RUBY_RELEASE_YEAR 2021
#define RUBY_RELEASE_MONTH 4