diff options
author | nagachika <nagachika@ruby-lang.org> | 2021-03-20 16:15:35 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2021-03-20 16:15:35 +0900 |
commit | ec779aa56f4d6df465e721818d73d0d48fdf03f2 (patch) | |
tree | b6b4db09f9f0dcec4ccf76c2489b3ff417cf0d7f /eval_intern.h | |
parent | 6e962f02b266c3a6c47e50cf2e9ab7b1db25e515 (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(-)
Diffstat (limited to 'eval_intern.h')
-rw-r--r-- | eval_intern.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/eval_intern.h b/eval_intern.h index aa07ce30ed..a8eb828597 100644 --- a/eval_intern.h +++ b/eval_intern.h @@ -291,7 +291,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 |