mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Fix corruption of encoding name string
[Bug #20595] enc_set_default_encoding will free the C string if the encoding is nil, but the C string can be used by the encoding name string. This will cause the encoding name string to be corrupted. Consider the following code: Encoding.default_internal = Encoding::ASCII_8BIT names = Encoding.default_internal.names p names Encoding.default_internal = nil p names It outputs: ["ASCII-8BIT", "BINARY", "internal"] ["ASCII-8BIT", "BINARY", "\x00\x00\x00\x00\x00\x00\x00\x00"] Co-authored-by: Matthew Valentine-House <matt@eightbitraptor.com>
This commit is contained in:
parent
815b345b41
commit
c6a0d03649
2 changed files with 12 additions and 1 deletions
|
@ -1301,7 +1301,7 @@ enc_names_i(st_data_t name, st_data_t idx, st_data_t args)
|
|||
VALUE *arg = (VALUE *)args;
|
||||
|
||||
if ((int)idx == (int)arg[0]) {
|
||||
VALUE str = rb_fstring_cstr((char *)name);
|
||||
VALUE str = rb_interned_str_cstr((char *)name);
|
||||
rb_ary_push(arg[1], str);
|
||||
}
|
||||
return ST_CONTINUE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue