Skip to content

Commit

Permalink
* lib/pp.rb (guard_inspect_key): untrust internal hash to prevent
Browse files Browse the repository at this point in the history
  unexpected SecurityError.

* test/ruby/test_object.rb: add a test for [ruby-dev:38982].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
mame committed Aug 4, 2009
1 parent 5ea7e7f commit 528574c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Wed Aug 5 01:38:27 2009 Yusuke Endoh <[email protected]>

* lib/pp.rb (guard_inspect_key): untrust internal hash to prevent
unexpected SecurityError.

* test/ruby/test_object.rb: add a test for [ruby-dev:38982].

Wed Aug 5 00:33:05 2009 Nobuyoshi Nakada <[email protected]>

* lib/rdoc/parser/c.rb: fixed a small error in the documentation.
Expand Down
6 changes: 3 additions & 3 deletions lib/pp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ class << self
module PPMethods
def guard_inspect_key
if Thread.current[:__recursive_key__] == nil
Thread.current[:__recursive_key__] = {}
Thread.current[:__recursive_key__] = {}.untrust
end

if Thread.current[:__recursive_key__][:inspect] == nil
Thread.current[:__recursive_key__][:inspect] = {}
Thread.current[:__recursive_key__][:inspect] = {}.untrust
end

save = Thread.current[:__recursive_key__][:inspect]

begin
Thread.current[:__recursive_key__][:inspect] = {}
Thread.current[:__recursive_key__][:inspect] = {}.untrust
yield
ensure
Thread.current[:__recursive_key__][:inspect] = save
Expand Down
36 changes: 36 additions & 0 deletions test/ruby/test_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,40 @@ def test_to_s
assert_equal(true, s.untrusted?)
assert_equal(true, s.tainted?)
end

def test_exec_recursive
Thread.current[:__recursive_key__] = nil
a = [[]]
a.inspect

assert_nothing_raised do
-> do
$SAFE = 4
begin
a.hash
rescue ArgumentError
end
end.call
end

-> do
assert_nothing_raised do
$SAFE = 4
a.inspect
end
end.call

-> do
o = Object.new
def o.to_ary(x); end
def o.==(x); $SAFE = 4; false; end
a = [[o]]
b = []
b << b

assert_nothing_raised do
b == a
end
end.call
end
end

0 comments on commit 528574c

Please sign in to comment.