1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/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
..
-test- merge revision(s) 3f9562015e651735bfc2fdd14e8f6963b673e22a,c06ddfee878524168e4af07443217ed2f8d0954b,3b3b4a44e5: [Backport #15792] 2019-08-26 15:58:57 +00:00
bigdecimal bigdecimal: version 1.3.4 2017-12-24 06:22:41 +00:00
cgi/escape cgi/util.rb: Don't escape tilde in #escape 2017-05-17 12:34:59 +00:00
continuation Update dependencies 2016-07-06 05:48:13 +00:00
coverage ext/coverage/coverage.c: remove COVERAGE_EXPERIMENTAL_MODE 2017-12-12 00:20:58 +00:00
date merge revision(s) 62572: [Backport #14549] 2018-02-28 09:52:40 +00:00
dbm Bump dbm-1.0.0 for released version. 2017-12-06 08:32:01 +00:00
digest Remove digest.gemspec for default gems. 2017-12-19 02:43:09 +00:00
etc Bump version to etc-1.0.0 as default gems. 2017-12-13 05:52:47 +00:00
fcntl Bump version to fcntl-1.0.0 as default gems. 2017-12-11 06:03:53 +00:00
fiber Update dependencies 2016-07-06 05:48:13 +00:00
fiddle Bump fiddle-1.0.0 for released version. 2017-12-06 08:35:13 +00:00
gdbm Bump gdbm-2.0.0 for released versionn. 2017-12-06 08:34:34 +00:00
io gperf.sed: static declarations 2017-12-15 14:42:43 +00:00
json Merge json-2.1.0 from https://github.com/flori/json 2017-06-16 03:04:46 +00:00
nkf ext: check if null byte is contained 2017-09-30 08:35:23 +00:00
objspace Fix imemo_name to dump new imemo types 2017-12-21 00:40:54 +00:00
openssl Import Ruby/OpenSSL 2.1.2. 2018-10-17 15:26:54 +00:00
pathname pathname.c: improve docs for Pathname 2017-11-07 20:14:46 +00:00
psych Merge psych-3.0.2 from ruby/psych. 2017-12-19 09:44:33 +00:00
pty merge revision(s) 67183: [Backport #15607] 2019-03-06 11:32:02 +00:00
racc/cparse Update dependencies 2016-07-06 05:48:13 +00:00
rbconfig/sizeof configure.ac 2017-09-29 13:21:17 +00:00
readline ext: check if null byte is contained 2017-09-30 08:35:23 +00:00
ripper merge revision(s) 67200: [Backport #15648] 2019-03-13 00:32:12 +00:00
rubyvm get rid of test failures introduced at r56848 2016-11-20 06:19:05 +00:00
sdbm Revert wrong commit r62976-r62978 2018-03-28 13:45:50 +00:00
socket merge revision(s) 64636,64637: [Backport #15659] 2019-03-12 12:59:25 +00:00
stringio [DOC] StringIO#write accepts multiple arguments since r60377 [ci skip] 2017-12-22 03:35:54 +00:00
strscan Update version of strscan to 1.0.0. 2017-12-19 03:12:22 +00:00
syslog ext: check if null byte is contained 2017-09-30 08:35:23 +00:00
win32 Fixed misspelling words. 2017-10-22 11:27:06 +00:00
win32ole hide internal data objects 2017-12-04 07:37:21 +00:00
zlib Bump version to zlib-1.0.0 as default gems. 2017-12-11 08:37:49 +00:00
.document ext/.document: follow-up r59734 2017-09-03 13:31:34 +00:00
extmk.rb ext/extmk.rb: colorize notes [Feature #13302] 2017-04-21 03:01:12 +00:00
Setup Removed deprecated extensions of mathn. 2017-04-20 08:21:24 +00:00
Setup.atheos * ext/tk: Tk is removed from stdlib. [Feature #8539] 2016-08-09 06:44:45 +00:00
Setup.nt * ext/tk: Tk is removed from stdlib. [Feature #8539] 2016-08-09 06:44:45 +00:00