Skip to content

Commit d7ef972

Browse files
authored
[Bug #22063] Reject NaN Regexp timeout values
1 parent d0ea61c commit d7ef972

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

re.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3971,7 +3971,7 @@ static void
39713971
set_timeout(rb_hrtime_t *hrt, VALUE timeout)
39723972
{
39733973
double timeout_d = NIL_P(timeout) ? 0.0 : NUM2DBL(timeout);
3974-
if (!NIL_P(timeout) && timeout_d <= 0) {
3974+
if (!NIL_P(timeout) && !(timeout_d > 0)) {
39753975
rb_raise(rb_eArgError, "invalid timeout: %"PRIsVALUE, timeout);
39763976
}
39773977
double2hrtime(hrt, timeout_d);

test/ruby/test_regexp.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,7 @@ def test_s_timeout_corner_cases
20352035
Regexp.timeout = 1e300
20362036
assert_equal(((1<<64)-1) / 1000000000.0, Regexp.timeout)
20372037
2038+
assert_raise(ArgumentError) { Regexp.timeout = Float::NAN }
20382039
assert_raise(ArgumentError) { Regexp.timeout = 0 }
20392040
assert_raise(ArgumentError) { Regexp.timeout = -1 }
20402041
@@ -2127,6 +2128,7 @@ def test_timeout_corner_cases
21272128
21282129
assert_equal(((1<<64)-1) / 1000000000.0, Regexp.new("foo", timeout: 1e300).timeout)
21292130
2131+
assert_raise(ArgumentError) { Regexp.new("foo", timeout: Float::NAN) }
21302132
assert_raise(ArgumentError) { Regexp.new("foo", timeout: 0) }
21312133
assert_raise(ArgumentError) { Regexp.new("foo", timeout: -1) }
21322134
end;

0 commit comments

Comments
 (0)