1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/-ext-
usa 689a6a0a76 merge revision(s) 3f9562015e651735bfc2fdd14e8f6963b673e22a,c06ddfee878524168e4af07443217ed2f8d0954b,3b3b4a44e5: [Backport #15792]
Get rid of indirect sharing

	* string.c (str_duplicate): share the root shared string if the
	  original string is already sharing, so that all shared strings
	  refer the root shared string directly.  indirect sharing can
	  cause a dangling pointer.

	[Bug #15792]

	str_duplicate: Don't share with a frozen shared string

	This is a follow up for 3f9562015e.
	Before this commit, it was possible to create a shared string which
	shares with another shared string by passing a frozen shared string
	to `str_duplicate`.

	Such string looks like:

	```
	 --------                    -----------------
	 | root | ------ owns -----> | root's buffer |
	 --------                    -----------------
	     ^                             ^   ^
	 -----------                       |   |
	 | shared1 | ------ references -----   |
	 -----------                           |
	     ^                                 |
	 -----------                           |
	 | shared2 | ------ references ---------
	 -----------
	```

	This is bad news because `rb_fstring(shared2)` can make `shared1`
	independent, which severs the reference from `shared1` to `root`:

	```c
	/* from fstr_update_callback() */
	str = str_new_frozen(rb_cString, shared2);  /* can return shared1 */
	if (STR_SHARED_P(str)) { /* shared1 is also a shared string */
	    str_make_independent(str);  /* no frozen check */
	}
	```

	If `shared1` was the only reference to `root`, then `root` can be
	reclaimed by the GC, leaving `shared2` in a corrupted state:

	```
	 -----------                         --------------------
	 | shared1 | -------- owns --------> | shared1's buffer |
	 -----------                         --------------------
	      ^
	      |
	 -----------                         -------------------------
	 | shared2 | ------ references ----> | root's buffer (freed) |
	 -----------                         -------------------------
	```

	Here is a reproduction script for the situation this commit fixes.

	```ruby
	a = ('a' * 24).strip.freeze.strip
	-a
	p a
	4.times { GC.start }
	p a
	```

	 - string.c (str_duplicate): always share with the root string when
	   the original is a shared string.
	 - test_rb_str_dup.rb: specifically test `rb_str_dup` to make
	   sure it does not try to share with a shared string.

	[Bug #15792]

	Closes: https://github.com/ruby/ruby/pull/2159

	Update dependencies


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@67766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-08-26 15:58:57 +00:00
..
array
bignum numeric.c: fix return value on big 0 2016-11-01 12:35:32 +00:00
bug_reporter
class
debug merge revision(s) 64799,64800,64801: [Backport #15105] 2018-11-28 13:55:17 +00:00
exception eval.c: hide internal objects 2017-02-03 06:23:34 +00:00
file
float
funcall merge revision(s) 62116,62151: [Backport #14425] 2018-02-20 20:11:47 +00:00
gvl
hash
integer merge revision(s) 67203: [Backport #15651] 2019-03-11 12:51:59 +00:00
iseq_load test_iseq_load.rb: refine test_require_integration 2017-02-02 05:43:58 +00:00
iter passed block should keep the lambda-ness 2017-01-01 08:22:02 +00:00
load load.c: fix rb_load_protect condition 2017-09-24 05:22:23 +00:00
marshal
method * basictest/test.rb: Adjust spaces in class declarations 2016-10-07 05:18:57 +00:00
num2int Rename RbConfig::Limits as RbConfig::LIMITS 2017-04-06 02:10:40 +00:00
path_to_class
popen_deadlock
postponed_job Remove unnecessary require 'thread' 2017-10-08 07:00:01 +00:00
proc
rational
st
string merge revision(s) 3f9562015e651735bfc2fdd14e8f6963b673e22a,c06ddfee878524168e4af07443217ed2f8d0954b,3b3b4a44e5: [Backport #15792] 2019-08-26 15:58:57 +00:00
struct fix RSTRUCT_LEN macro in public C API 2017-04-15 00:46:00 +00:00
symbol symbol/noninterned_name.rb 2016-11-12 08:16:58 +00:00
thread_fd_close Fix test-all tests to avoid creating report_on_exception warnings 2017-12-12 18:44:49 +00:00
time
tracepoint
typeddata gc.c: expand sorted pages 2017-06-22 00:59:54 +00:00
vm
wait_for_single_fd rb_wait_for_single_fd: do not OOM or segfault with invalid FD on select() 2017-05-27 08:26:47 +00:00
win32 test_dln.rb: fix path separator on MinGW 2017-09-28 13:55:48 +00:00
test_bug-3571.rb
test_bug-5832.rb
test_notimplement.rb
test_printf.rb sprintf.c: NULL as str 2017-09-09 09:16:59 +00:00
test_recursion.rb
test_scan_args.rb non-keywords hash 2017-08-20 06:08:25 +00:00