summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-enumerator
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-09-19 20:53:32 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2018-11-19 11:28:51 +0900
commitafca99a40b8a3415b3a9a0e8fc41c93ddcbb11d8 (patch)
tree6ecbeb3c8a562ce64713ccd4d2d6b1d12e6b5fa2 /mrbgems/mruby-enumerator
parent426c1f9e0b77a27d5384ccdee7f7a49eef0e2ed0 (diff)
downloadmruby-afca99a40b8a3415b3a9a0e8fc41c93ddcbb11d8.tar.gz
mruby-afca99a40b8a3415b3a9a0e8fc41c93ddcbb11d8.zip
Remove implicit conversion using `to_int` method.
The ISO standard does not include implicit type conversion using `to_int`. This implicit conversion often causes vulnerability. There will be no more attacks like #4120. In addition, we have added internal convenience method `__to_int` which does type check and conversion (from floats).
Diffstat (limited to 'mrbgems/mruby-enumerator')
-rw-r--r--mrbgems/mruby-enumerator/mrblib/enumerator.rb8
-rw-r--r--mrbgems/mruby-enumerator/test/enumerator.rb6
2 files changed, 3 insertions, 11 deletions
diff --git a/mrbgems/mruby-enumerator/mrblib/enumerator.rb b/mrbgems/mruby-enumerator/mrblib/enumerator.rb
index dbc7d3004..6dd971f3a 100644
--- a/mrbgems/mruby-enumerator/mrblib/enumerator.rb
+++ b/mrbgems/mruby-enumerator/mrblib/enumerator.rb
@@ -157,12 +157,10 @@ class Enumerator
def with_index(offset=0, &block)
return to_enum :with_index, offset unless block
- offset = if offset.nil?
- 0
- elsif offset.respond_to?(:to_int)
- offset.to_int
+ if offset.nil?
+ offset = 0
else
- raise TypeError, "no implicit conversion of #{offset.class} into Integer"
+ offset = offset.__to_int
end
n = offset - 1
diff --git a/mrbgems/mruby-enumerator/test/enumerator.rb b/mrbgems/mruby-enumerator/test/enumerator.rb
index ef4970883..f3bd1bdba 100644
--- a/mrbgems/mruby-enumerator/test/enumerator.rb
+++ b/mrbgems/mruby-enumerator/test/enumerator.rb
@@ -54,12 +54,6 @@ assert 'Enumerator#with_index' do
assert_equal [[[1, 10], 20], [[2, 11], 21], [[3, 12], 22]], a
end
-assert 'Enumerator#with_index nonnum offset' do
- s = Object.new
- def s.to_int; 1 end
- assert_equal([[1,1],[2,2],[3,3]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a)
-end
-
assert 'Enumerator#with_index string offset' do
assert_raise(TypeError){ @obj.to_enum(:foo, 1, 2, 3).with_index('1').to_a }
end