ruby-changes:45981
From: naruse <ko1@a...>
Date: Wed, 22 Mar 2017 14:54:28 +0900 (JST)
Subject: [ruby-changes:45981] naruse:r58052 (ruby_2_4): merge revision(s) 58040, 58041:
naruse 2017-03-22 14:54:22 +0900 (Wed, 22 Mar 2017) New Revision: 58052 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58052 Log: merge revision(s) 58040,58041: 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_4/ Modified files: branches/ruby_2_4/ext/stringio/stringio.c branches/ruby_2_4/test/stringio/test_stringio.rb branches/ruby_2_4/version.h Index: ruby_2_4/ext/stringio/stringio.c =================================================================== --- ruby_2_4/ext/stringio/stringio.c (revision 58051) +++ ruby_2_4/ext/stringio/stringio.c (revision 58052) @@ -767,13 +767,15 @@ strio_ungetc(VALUE self, VALUE c) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ext/stringio/stringio.c#L767 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); Index: ruby_2_4/version.h =================================================================== --- ruby_2_4/version.h (revision 58051) +++ ruby_2_4/version.h (revision 58052) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1 #define RUBY_VERSION "2.4.1" #define RUBY_RELEASE_DATE "2017-03-22" -#define RUBY_PATCHLEVEL 110 +#define RUBY_PATCHLEVEL 111 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 3 Index: ruby_2_4/test/stringio/test_stringio.rb =================================================================== --- ruby_2_4/test/stringio/test_stringio.rb (revision 58051) +++ ruby_2_4/test/stringio/test_stringio.rb (revision 58052) @@ -453,6 +453,9 @@ class TestStringIO < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/stringio/test_stringio.rb#L453 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 Property changes on: ruby_2_4 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r58040-58041 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/