ruby-changes:47269
From: nobu <ko1@a...>
Date: Fri, 21 Jul 2017 22:30:54 +0900 (JST)
Subject: [ruby-changes:47269] nobu:r59384 (trunk): strscan.c: fix segfault in aref
nobu 2017-07-21 22:30:46 +0900 (Fri, 21 Jul 2017) New Revision: 59384 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59384 Log: strscan.c: fix segfault in aref * ext/strscan/strscan.c (strscan_aref): fix segfault after get_byte or getch which do not apply regexp. [ruby-core:82116] [Bug #13759] Modified files: trunk/ext/strscan/strscan.c trunk/test/strscan/test_stringscanner.rb Index: test/strscan/test_stringscanner.rb =================================================================== --- test/strscan/test_stringscanner.rb (revision 59383) +++ test/strscan/test_stringscanner.rb (revision 59384) @@ -718,4 +718,14 @@ class TestStringScanner < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/strscan/test_stringscanner.rb#L718 s.scan(/test strin/) assert_equal('#<StringScanner 10/16 "...strin" @ "g tes...">', s.inspect) end + + def test_aref_without_regex + s = StringScanner.new('abc') + s.get_byte + assert_nil(s[:c]) + assert_nil(s["c"]) + s.getch + assert_nil(s[:c]) + assert_nil(s["c"]) + end end Index: ext/strscan/strscan.c =================================================================== --- ext/strscan/strscan.c (revision 59383) +++ ext/strscan/strscan.c (revision 59384) @@ -1034,6 +1034,7 @@ strscan_aref(VALUE self, VALUE idx) https://github.com/ruby/ruby/blob/trunk/ext/strscan/strscan.c#L1034 idx = rb_sym2str(idx); /* fall through */ case T_STRING: + if (!p->regex) return Qnil; RSTRING_GETMEM(idx, name, i); i = name_to_backref_number(&(p->regs), p->regex, name, name + i, rb_enc_get(idx)); break; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/