[ruby-core:90629] [Ruby trunk Bug#15440] Freeze hash literals embedded in duphash instructions

From: merch-redmine@...
Date: 2018-12-20 06:24:52 UTC
List: ruby-core #90629
Issue #15440 has been reported by jeremyevans0 (Jeremy Evans).

----------------------------------------
Bug #15440: Freeze hash literals embedded in duphash instructions
https://bugs.ruby-lang.org/issues/15440

* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 2.6
* ruby -v: ruby 2.6.0dev (2018-12-20 trunk 66461) [x86_64-openbsd]
* Backport: 2.4: DONTNEED, 2.5: DONTNEED
----------------------------------------
Previously, these hash literals were not frozen, and thus could be
modified by ObjectSpace, resulting in undesired behavior.  Example
(run with --disable-gems):

~~~ ruby
require 'objspace'

def a(b={0=>1,1=>4,2=>17})
  b
end

p a
# => {0=>1, 1=>4, 2=>17}
ObjectSpace.each_object(Hash) do |a|
  a[3] = 8 if a.class == Hash && a[0] == 1 && a[1] == 4 && a[2] == 17
end
p a
# => {0=>1, 1=>4, 2=>17, 3=>8}
~~~

Attached is a patch that freezes such hashes, so attempting to
modify the object will raise a FrozenError.

It may be desirable to hide such hashes from ObjectSpace, since
they are internal, but I'm not sure how to do that.

---Files--------------------------------
0001-Freeze-hash-literals-embedded-in-duphash-instruction.patch (2.25 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next