diff options
author | Peter Zhu <peter@peterzhu.ca> | 2020-08-12 04:54:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-12 17:54:09 +0900 |
commit | 166cacc505e5a0d807712e9cb5b6919a7d190a6e (patch) | |
tree | bfecacac9a13ab87d5afe1b0fdc22ca79931706f /io.c | |
parent | e79cdcf61b0665d8a9bb309a607227de43e95673 (diff) | |
download | ruby-166cacc505e5a0d807712e9cb5b6919a7d190a6e.tar.gz |
Fix corruption in ARGF.inplace
Extension string stored in `ARGF.inplace` is created using an api
designed for C string constants to create a Ruby string that
points at another Ruby string. When the original string is swept,
the extension string gets corrupted.
Reproduction script (on MacOS):
```ruby
#!/usr/bin/ruby -pi.bak
BEGIN {
GC.start(full_mark: true)
arr = []
1000000.times do |x|
arr << "fooo#{x}"
end
}
puts "hello"
```
Co-Authored-By: Matt Valentine-House <31869+eightbitraptor@users.noreply.github.com>
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -12988,7 +12988,7 @@ opt_i_set(VALUE val, ID id, VALUE *var) void ruby_set_inplace_mode(const char *suffix) { - ARGF.inplace = !suffix ? Qfalse : !*suffix ? Qnil : rb_fstring_cstr(suffix); + ARGF.inplace = !suffix ? Qfalse : !*suffix ? Qnil : rb_str_new(suffix, strlen(suffix)); } /* |