Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromruby/ruby

Commit65d294a

Browse files
committed
merge revision(s)bc3ac18: [Backport #19748]
[Bug #19748] Fix out-of-bound access in `String#byteindex`--- string.c | 17 +++++++---------- test/ruby/test_string.rb | 3 +++ 2 files changed, 10 insertions(+), 10 deletions(-)
1 parent35cf3a5 commit65d294a

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

‎string.c‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4048,29 +4048,28 @@ rb_str_byteindex_m(int argc, VALUE *argv, VALUE str)
40484048
longpos;
40494049

40504050
if (rb_scan_args(argc,argv,"11",&sub,&initpos)==2) {
4051+
longslen=RSTRING_LEN(str);
40514052
pos=NUM2LONG(initpos);
4052-
}
4053-
else {
4054-
pos=0;
4055-
}
4056-
if (pos<0) {
4057-
pos+=RSTRING_LEN(str);
40584053
if (pos<0) {
4054+
pos+=slen;
4055+
}
4056+
if (pos<0||pos>slen) {
40594057
if (RB_TYPE_P(sub,T_REGEXP)) {
40604058
rb_backref_set(Qnil);
40614059
}
40624060
returnQnil;
40634061
}
40644062
}
4063+
else {
4064+
pos=0;
4065+
}
40654066

40664067
if (!str_check_byte_pos(str,pos)) {
40674068
rb_raise(rb_eIndexError,
40684069
"offset %ld does not land on character boundary",pos);
40694070
}
40704071

40714072
if (RB_TYPE_P(sub,T_REGEXP)) {
4072-
if (pos>RSTRING_LEN(str))
4073-
returnQnil;
40744073
if (rb_reg_search(sub,str,pos,0)<0) {
40754074
returnQnil;
40764075
}

‎test/ruby/test_string.rb‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3376,6 +3376,9 @@ def o.to_str; "bar"; end
33763376
assert_equal(6,S("にんにちは").byteindex(S("に"),6))
33773377
assert_equal(6,S("にんにちは").byteindex(/に./,6))
33783378
assert_raise(IndexError){S("にんにちは").byteindex(?に,7)}
3379+
3380+
s=S("foobarbarbaz")
3381+
assert !1000.times.any?{s.byteindex("",100_000_000)}
33793382
end
33803383

33813384
deftest_byterindex

‎version.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# defineRUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#defineRUBY_VERSION_TEENY 2
1313
#defineRUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#defineRUBY_PATCHLEVEL101
14+
#defineRUBY_PATCHLEVEL102
1515

1616
#include"ruby/version.h"
1717
#include"ruby/internal/abi.h"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp