1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Check pos and strlen on Regexp#index(str, pos) [ruby-core:23660]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24103 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2009-07-14 08:30:54 +00:00
parent 9681409e36
commit 6a3931e0f6
2 changed files with 7 additions and 0 deletions

View file

@ -1,3 +1,8 @@
Tue Jul 14 17:29:20 2009 NARUSE, Yui <naruse@ruby-lang.org>
* string.c (rb_str_index_m): return nil if pos is out of string.
[ruby-core:23660]
Tue Jul 14 16:13:04 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (rb_io_initialize): check if the descriptor can be accessed

View file

@ -2569,6 +2569,8 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)
switch (TYPE(sub)) {
case T_REGEXP:
if (pos > str_strlen(str, STR_ENC_GET(str)))
return Qnil;
pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos,
rb_enc_check(str, sub), single_byte_optimizable(str));