Project

General

Profile

Actions

Bug #15440

closed

Freeze hash literals embedded in duphash instructions

Added by jeremyevans0 (Jeremy Evans) about 6 years ago. Updated about 6 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 2.6.0dev (2018-12-20 trunk 66461) [x86_64-openbsd]
[ruby-core:90629]

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

Actions #1

Updated by ko1 (Koichi Sasada) about 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

Also available in: Atom PDF

Like0
Like0