summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrii Furmanets <furmanets.andriy@gmail.com>2026-05-11 13:25:29 +0300
committerGitHub <noreply@github.com>2026-05-11 10:25:29 +0000
commitd7ef97204d907561eb67828382f7bb17397313c6 (patch)
tree9a7dce92310e0bdeb54084ae62832638ef93740a
parentd0ea61cb87ea3a3d40ef6f90a5ff8dea75fa6f3a (diff)
[Bug #22063] Reject NaN Regexp timeout values
-rw-r--r--re.c2
-rw-r--r--test/ruby/test_regexp.rb2
2 files changed, 3 insertions, 1 deletions
diff --git a/re.c b/re.c
index bb6af74eb5..317790fba8 100644
--- a/re.c
+++ b/re.c
@@ -3971,7 +3971,7 @@ static void
set_timeout(rb_hrtime_t *hrt, VALUE timeout)
{
double timeout_d = NIL_P(timeout) ? 0.0 : NUM2DBL(timeout);
- if (!NIL_P(timeout) && timeout_d <= 0) {
+ if (!NIL_P(timeout) && !(timeout_d > 0)) {
rb_raise(rb_eArgError, "invalid timeout: %"PRIsVALUE, timeout);
}
double2hrtime(hrt, timeout_d);
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index d545d983dc..69e15bd4df 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -2035,6 +2035,7 @@ class TestRegexp < Test::Unit::TestCase
Regexp.timeout = 1e300
assert_equal(((1<<64)-1) / 1000000000.0, Regexp.timeout)
+ assert_raise(ArgumentError) { Regexp.timeout = Float::NAN }
assert_raise(ArgumentError) { Regexp.timeout = 0 }
assert_raise(ArgumentError) { Regexp.timeout = -1 }
@@ -2127,6 +2128,7 @@ class TestRegexp < Test::Unit::TestCase
assert_equal(((1<<64)-1) / 1000000000.0, Regexp.new("foo", timeout: 1e300).timeout)
+ assert_raise(ArgumentError) { Regexp.new("foo", timeout: Float::NAN) }
assert_raise(ArgumentError) { Regexp.new("foo", timeout: 0) }
assert_raise(ArgumentError) { Regexp.new("foo", timeout: -1) }
end;