diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-03 06:57:44 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-03 06:57:44 +0000 |
commit | 60f0e763a41636dd9284d4c0d56116fb7dfaae7d (patch) | |
tree | 42f96adb142f2df430516b702abf0bcb9ebf3822 /proc.c | |
parent | c7770f90bdcac04dad43ab38bef9c415433597cb (diff) | |
download | ruby-60f0e763a41636dd9284d4c0d56116fb7dfaae7d.tar.gz |
proc.c: fix segfault when no singleton class
* proc.c (rb_obj_singleton_method): bail out if the receiver does
not have the singleton class without accessing the origin class
not to segfault. [Bug #14658]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -1771,21 +1771,23 @@ VALUE rb_obj_singleton_method(VALUE obj, VALUE vid) { const rb_method_entry_t *me; - VALUE klass = RCLASS_ORIGIN(rb_singleton_class_get(obj)); + VALUE klass = rb_singleton_class_get(obj); ID id = rb_check_id(&vid); + if (NIL_P(klass) || NIL_P(klass = RCLASS_ORIGIN(klass))) { + undef: + rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'", + obj, vid); + } if (!id) { - if (!NIL_P(klass) && - respond_to_missing_p(klass, obj, vid, FALSE)) { + if (respond_to_missing_p(klass, obj, vid, FALSE)) { id = rb_intern_str(vid); return mnew_missing(klass, obj, id, rb_cMethod); } - undef: - rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'", - obj, vid); + goto undef; } - if (NIL_P(klass) || - UNDEFINED_METHOD_ENTRY_P(me = rb_method_entry_at(klass, id)) || + me = rb_method_entry_at(klass, id); + if (UNDEFINED_METHOD_ENTRY_P(me) || UNDEFINED_REFINED_METHOD_P(me->def)) { vid = ID2SYM(id); goto undef; |