diff options
| author | Andrii Furmanets <furmanets.andriy@gmail.com> | 2026-05-11 13:25:29 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-11 10:25:29 +0000 |
| commit | d7ef97204d907561eb67828382f7bb17397313c6 (patch) | |
| tree | 9a7dce92310e0bdeb54084ae62832638ef93740a | |
| parent | d0ea61cb87ea3a3d40ef6f90a5ff8dea75fa6f3a (diff) | |
[Bug #22063] Reject NaN Regexp timeout values
| -rw-r--r-- | re.c | 2 | ||||
| -rw-r--r-- | test/ruby/test_regexp.rb | 2 |
2 files changed, 3 insertions, 1 deletions
@@ -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; |
