Project

General

Profile

Bug #15440

Freeze hash literals embedded in duphash instructions

Added by jeremyevans0 (Jeremy Evans) 7 months ago. Updated 7 months ago.

Status:
Closed
Priority:
Normal
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

Associated revisions

Revision 2a70f68c
Added by ko1 (Koichi Sasada) 7 months ago

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 66466
Added by ko1 (Koichi Sasada) 7 months ago

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.

Revision 66466
Added by ko1 (Koichi Sasada) 7 months ago

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.

History

#1

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

Also available in: Atom PDF