From 6a3931e0f630f56d4acd2b232f58c0225f03f52b Mon Sep 17 00:00:00 2001 From: naruse Date: Tue, 14 Jul 2009 08:30:54 +0000 Subject: [PATCH] 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 --- ChangeLog | 5 +++++ string.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index a2f1ebf5ee..750bd06c03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Jul 14 17:29:20 2009 NARUSE, Yui + + * 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 * io.c (rb_io_initialize): check if the descriptor can be accessed diff --git a/string.c b/string.c index 9418bfe2ca..493ef5d87b 100644 --- a/string.c +++ b/string.c @@ -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));