[ruby-cvs:66532] normal:r59354 (trunk): hash: keep fstrings of tainted strings for string keys

normal at ruby-lang.org normal at ruby-lang.org
Tue Jul 18 11:29:59 JST 2017


normal	2017-07-18 11:29:59 +0900 (Tue, 18 Jul 2017)

  New Revision: 59354

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

  Log:
    hash: keep fstrings of tainted strings for string keys
    
    The same hash keys may be loaded from tainted data sources
    frequently (e.g. parsing headers from socket or loading
    YAML data from a file).  If a non-tainted fstring already
    exists (because the application expects the hash key),
    cache and deduplicate the tainted version in the new
    tainted_frozen_strings table.
    
    For non-embedded strings, this also allows sharing with the
    underlying malloc-ed data.
    
    * vm_core.h (rb_vm_struct): add tainted_frozen_strings
    * vm.c (ruby_vm_destruct): free tainted_frozen_strings
      (Init_vm_objects): initialize tainted_frozen_strings
      (rb_vm_tfstring_table): accessor for tainted_frozen_strings
    * internal.h: declare rb_fstring_existing, rb_vm_tfstring_table
    * hash.c (fstring_existing_str): remove (moved to string.c)
      (hash_aset_str): use rb_fstring_existing
    * string.c (rb_fstring_existing): new, based on fstring_existing_str
      (tainted_fstr_update): new
      (rb_fstring_existing0): new, based on fstring_existing_str
      (rb_tainted_fstring_existing): new, special case for tainted strings
      (rb_str_free): delete from tainted_frozen_strings table
    * test/ruby/test_optimization.rb (test_hash_reuse_fstring): new test
      [ruby-core:82012] [Bug #13737]

  Modified files:
    trunk/hash.c
    trunk/internal.h
    trunk/string.c
    trunk/test/ruby/test_optimization.rb
    trunk/vm.c
    trunk/vm_core.h


More information about the ruby-cvs mailing list