[ruby-cvs:73565] nobu:r66464 (trunk): Freeze hash literals embedded in duphash instructions

nobu at ruby-lang.org nobu at ruby-lang.org
Thu Dec 20 15:44:50 JST 2018


nobu	2018-12-20 15:44:50 +0900 (Thu, 20 Dec 2018)

  New Revision: 66464

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66464

  Log:
    Freeze hash literals embedded in duphash instructions
    
    Previously, these hash literals were not frozen, and thus could be
    modified by ObjectSpace, resulting in undesired behavior.  Example:
    
    ```ruby
    require 'objspace'
    
    def a(b={0=>1,1=>4,2=>17})
      b
    end
    
    p a
    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
    ```
    
    It may be desirable to hide such hashes from ObjectSpace, since
    they are internal, but I'm not sure how to do that.
    
    From: Jeremy Evans <code at jeremyevans.net>

  Modified files:
    trunk/compile.c
    trunk/test/ruby/test_literal.rb


More information about the ruby-cvs mailing list