From a680ee9ffa6eeaafd6efe52edbe5ed00e8620cb0 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 24 Apr 2014 03:08:49 +0000 Subject: [PATCH] parse.y: check for symbol * parse.y (rb_sym2id, rb_sym2id_without_pindown): reject non-symbol values. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- parse.y | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/parse.y b/parse.y index 7820b0b4ac..195df58828 100644 --- a/parse.y +++ b/parse.y @@ -10768,17 +10768,24 @@ lookup_id_str(ID id, st_data_t *data) return FALSE; } +static void +must_be_dynamic_symbol(VALUE x) +{ + if (SPECIAL_CONST_P(x) || BUILTIN_TYPE(x) != T_SYMBOL) { + rb_raise(rb_eTypeError, "wrong argument type %s (expected Symbol)", + rb_builtin_class_name(x)); + } +} + ID rb_sym2id(VALUE x) { if (STATIC_SYM_P(x)) { return RSHIFT((unsigned long)(x),RUBY_SPECIAL_SHIFT); } - else if (!SPECIAL_CONST_P(x) && BUILTIN_TYPE(x) == T_SYMBOL) { - return rb_pin_dynamic_symbol(x); - } else { - return 0; + must_be_dynamic_symbol(x); + return rb_pin_dynamic_symbol(x); } } @@ -10788,11 +10795,9 @@ rb_sym2id_without_pindown(VALUE x) if (STATIC_SYM_P(x)) { return RSHIFT((unsigned long)(x),RUBY_SPECIAL_SHIFT); } - else if (!SPECIAL_CONST_P(x) && BUILTIN_TYPE(x) == T_SYMBOL) { - return (ID)x; - } else { - return 0; + must_be_dynamic_symbol(x); + return (ID)x; } }