ruby-changes:47557
From: glass <ko1@a...>
Date: Mon, 28 Aug 2017 19:55:43 +0900 (JST)
Subject: [ruby-changes:47557] glass:r59673 (trunk): string.c: fix potential bug in String#split
glass 2017-08-28 19:55:37 +0900 (Mon, 28 Aug 2017) New Revision: 59673 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59673 Log: string.c: fix potential bug in String#split * string.c (rb_str_split_m): fix potential bug when rb_memsearch() matches a octet in the middle of a multi-byte character sequence. Modified files: trunk/string.c Index: string.c =================================================================== --- string.c (revision 59672) +++ string.c (revision 59673) @@ -7469,7 +7469,8 @@ rb_str_split_m(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/string.c#L7469 } else if (split_type == string) { char *ptr = RSTRING_PTR(str); - char *temp = ptr; + char *str_start = ptr; + char *substr_start = ptr; char *eptr = RSTRING_END(str); char *sptr = RSTRING_PTR(spat); long slen = RSTRING_LEN(spat); @@ -7484,11 +7485,13 @@ rb_str_split_m(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/string.c#L7485 ptr = t; continue; } - rb_ary_push(result, rb_str_subseq(str, ptr - temp, end)); + rb_ary_push(result, rb_str_subseq(str, substr_start - str_start, + (ptr+end) - substr_start)); ptr += end + slen; + substr_start = ptr; if (!NIL_P(limit) && lim <= ++i) break; } - beg = ptr - temp; + beg = ptr - str_start; } else { char *ptr = RSTRING_PTR(str); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/