ruby-changes:46089
From: nagachika <ko1@a...>
Date: Tue, 28 Mar 2017 00:36:01 +0900 (JST)
Subject: [ruby-changes:46089] nagachika:r58160 (ruby_2_3): merge revision(s) 58040, 58041: [Backport #13353]
nagachika 2017-03-28 00:35:54 +0900 (Tue, 28 Mar 2017) New Revision: 58160 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58160 Log: merge revision(s) 58040,58041: [Backport #13353] stringio.c: check character code * ext/stringio/stringio.c (strio_ungetc): check if the character code is valid in the encoding. reported by Ahmad Sherif (ahmadsherif) at https://hackerone.com/reports/209593. stringio.c: check range * ext/stringio/stringio.c (strio_ungetc): raise RangeError instead of TypeError at too big value, as well as IO#ungetc. Modified directories: branches/ruby_2_3/ Modified files: branches/ruby_2_3/ext/stringio/stringio.c branches/ruby_2_3/test/stringio/test_stringio.rb branches/ruby_2_3/version.h Index: ruby_2_3/version.h =================================================================== --- ruby_2_3/version.h (revision 58159) +++ ruby_2_3/version.h (revision 58160) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1 #define RUBY_VERSION "2.3.3" #define RUBY_RELEASE_DATE "2017-03-28" -#define RUBY_PATCHLEVEL 269 +#define RUBY_PATCHLEVEL 270 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 3 Index: ruby_2_3/test/stringio/test_stringio.rb =================================================================== --- ruby_2_3/test/stringio/test_stringio.rb (revision 58159) +++ ruby_2_3/test/stringio/test_stringio.rb (revision 58160) @@ -390,6 +390,9 @@ class TestStringIO < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/stringio/test_stringio.rb#L390 f.ungetc("y".ord) assert_equal("y", f.getc) assert_equal("2", f.getc) + + assert_raise(RangeError) {f.ungetc(0x1ffffff)} + assert_raise(RangeError) {f.ungetc(0xffffffffffffff)} ensure f.close unless f.closed? end Index: ruby_2_3/ext/stringio/stringio.c =================================================================== --- ruby_2_3/ext/stringio/stringio.c (revision 58159) +++ ruby_2_3/ext/stringio/stringio.c (revision 58160) @@ -741,13 +741,15 @@ strio_ungetc(VALUE self, VALUE c) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ext/stringio/stringio.c#L741 check_modifiable(ptr); if (NIL_P(c)) return Qnil; - if (FIXNUM_P(c)) { - int cc = FIX2INT(c); + if (RB_INTEGER_TYPE_P(c)) { + int len, cc = NUM2INT(c); char buf[16]; enc = rb_enc_get(ptr->string); + len = rb_enc_codelen(cc, enc); + if (len <= 0) rb_enc_uint_chr(cc, enc); rb_enc_mbcput(cc, buf, enc); - return strio_unget_bytes(ptr, buf, rb_enc_codelen(cc, enc)); + return strio_unget_bytes(ptr, buf, len); } else { SafeStringValue(c); Property changes on: ruby_2_3 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r58040-58041 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/