diff options
author | Peter Zhu <[email protected]> | 2024-06-26 16:12:53 -0400 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2024-06-27 09:47:22 -0400 |
commit | c6a0d03649c686a537c1f513a1e32205ac6a6512 (patch) | |
tree | dc5dc20efa563cd4208f82cd7f8aa65f1f53b72d /encoding.c | |
parent | 815b345b4169f4762510479df6cf73c91362cdeb (diff) |
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 <[email protected]>
Diffstat (limited to 'encoding.c')
-rw-r--r-- | encoding.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/encoding.c b/encoding.c index 480cc8bdc6..a09d84b757 100644 --- a/encoding.c +++ b/encoding.c @@ -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; |