summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
authorKenichi Kamiya <kachick1@gmail.com>2021-03-28 08:47:42 +0900
committerGitHub <noreply@github.com>2021-03-28 08:47:42 +0900
commit0a544c0c35f7445d69402d7c53d825384c728017 (patch)
tree12292326abb521d9e3096ac6e7b76314c6677b89 /error.c
parent95d9fe9538441eb57ee6752aa1c5088fc6608e34 (diff)
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
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4328 Merged-By: nobu <nobu@ruby-lang.org>
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 9da51a3a39..5dd6b2b765 100644
--- a/error.c
+++ b/error.c
@@ -1965,8 +1965,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);
}