From 745565052a915f8815cd5d3cf299ab4cba20c57c Mon Sep 17 00:00:00 2001 From: usa Date: Tue, 27 Dec 2016 10:52:35 +0000 Subject: merge revision(s) 57078: [Backport #13034] encoding.c: handle needmore error from rb_enc_precise_mbclen() rb_enc_ascget() erroneously reports success even if the given byte sequence is incomplete, for non-ASCII compatible encoding strings. rb_enc_precise_mbclen() may return a negative value on error, and thus rb_enc_ascget() must not store the return value in 'unsigned int'; otherwise the subsequent MBCLEN_CHARFOUND_P() check won't catch the error. [ruby-core:78646] [Bug #13034] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@57217 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 13 +++++++++++++ encoding.c | 3 ++- test/ruby/test_regexp.rb | 4 ++++ version.h | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 44b90606c3..ac1273c03d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Tue Dec 27 19:51:43 2016 Kazuki Yamaguchi + + * encoding.c (rb_enc_ascget): handle needmore error from + rb_enc_precise_mbclen(). + + rb_enc_ascget() erroneously reports success even if the given byte + sequence is incomplete, for non-ASCII compatible encoding strings. + + rb_enc_precise_mbclen() may return a negative value on error, and thus + rb_enc_ascget() must not store the return value in 'unsigned int'; + otherwise the subsequent MBCLEN_CHARFOUND_P() check won't catch the + error. [Bug #13034] + Tue Dec 27 19:49:01 2016 Shugo Maeda * cont.c, eval.c, eval_error.c, thread.c, vm_eval.c, vm_trace.c: add diff --git a/encoding.c b/encoding.c index 07b32f5f83..e49d148d43 100644 --- a/encoding.c +++ b/encoding.c @@ -975,7 +975,8 @@ rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc) int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc) { - unsigned int c, l; + unsigned int c; + int l; if (e <= p) return -1; if (rb_enc_asciicompat(enc)) { diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 144986dd56..39ba6dc760 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -492,6 +492,10 @@ class TestRegexp < Test::Unit::TestCase assert_equal("\\v", Regexp.quote("\v")) assert_equal("\u3042\\t", Regexp.quote("\u3042\t")) assert_equal("\\t\xff", Regexp.quote("\t" + [0xff].pack("C"))) + + bug13034 = '[ruby-core:78646] [Bug #13034]' + str = "\x00".force_encoding("UTF-16BE") + assert_equal(str, Regexp.quote(str), bug13034) end def test_try_convert diff --git a/version.h b/version.h index 202743fbc4..c5ea0fead2 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.2.7" #define RUBY_RELEASE_DATE "2016-12-27" -#define RUBY_PATCHLEVEL 407 +#define RUBY_PATCHLEVEL 408 #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 12 -- cgit v1.2.3