summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
authorNARUSE, Yui <naruse@airemix.jp>2021-04-02 16:09:09 +0900
committerNARUSE, Yui <naruse@airemix.jp>2021-04-02 16:09:09 +0900
commit6abb8ee711a941b7ad31d21fdb429750f7ea4463 (patch)
treec774899b4069549383a52c7f949b1e64f8e3d648 /error.c
parent0315e1e5ca0722f9dffeae70b860c19de303e339 (diff)
merge revision(s) 0a544c0c35f7445d69402d7c53d825384c728017: [Backport #17754]
Fix segmentation fault when `Module#name` returns non string value [Bug #17754] * Add test for NoMethodError#to_s does not segfault * Ensure no segfault even if Module#name is overridden --- error.c | 4 +++- test/ruby/test_nomethod_error.rb | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-)
Diffstat (limited to 'error.c')
-rw-r--r--error.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/error.c b/error.c
index d1dfd03a9d..73705b0b58 100644
--- a/error.c
+++ b/error.c
@@ -1950,8 +1950,10 @@ name_err_mesg_to_str(VALUE obj)
d = rb_protect(name_err_mesg_receiver_name, obj, &state);
if (state || d == Qundef || d == Qnil)
d = rb_protect(rb_inspect, obj, &state);
- if (state)
+ if (state) {
rb_set_errinfo(Qnil);
+ }
+ d = rb_check_string_type(d);
if (NIL_P(d)) {
d = rb_any_to_s(obj);
}