Actions
Bug #15440
closedFreeze hash literals embedded in duphash instructions
Description
Previously, these hash literals were not frozen, and thus could be
modified by ObjectSpace, resulting in undesired behavior. Example
(run with --disable-gems):
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
Updated by ko1 (Koichi Sasada) almost 6 years ago
- Status changed from Open to Closed
Applied in changeset trunk|r66466.
hide iseq operand object for duphash. [Bug #15440]
-
compile.c (compile_array): hide source Hash object.
-
hash.c (rb_hash_resurrect): introduced to dup Hash object
using rb_cHash.
Actions
Like0
Like0