ruby-changes:28052
From: nobu <ko1@a...>
Date: Thu, 4 Apr 2013 17:19:02 +0900 (JST)
Subject: [ruby-changes:28052] nobu:r40104 (trunk): object.c: avoid inadvertent symbol creation
nobu 2013-04-04 17:18:54 +0900 (Thu, 04 Apr 2013) New Revision: 40104 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40104 Log: object.c: avoid inadvertent symbol creation * object.c (rb_mod_const_set): fix symbol name check. (rb_obj_ivar_set): ditto. (rb_mod_cvar_set): ditto. Modified files: trunk/object.c Index: object.c =================================================================== --- object.c (revision 40103) +++ object.c (revision 40104) @@ -2043,11 +2043,22 @@ rb_mod_const_get(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/object.c#L2043 static VALUE rb_mod_const_set(VALUE mod, VALUE name, VALUE value) { - if (!SYMBOL_P(name) && !rb_is_const_name(name)) { + ID id; + if (SYMBOL_P(name)) { + id = SYM2ID(name); + if (!rb_is_const_id(id)) { + rb_name_error(id, "wrong constant name %"PRIsVALUE, + QUOTE_ID(id)); + } + } + else if (!rb_is_const_name(name)) { rb_name_error_str(name, "wrong constant name %"PRIsVALUE, QUOTE(name)); } - rb_const_set(mod, rb_to_id(name), value); + else { + id = rb_to_id(name); + } + rb_const_set(mod, id, value); return value; } @@ -2164,11 +2175,23 @@ rb_obj_ivar_get(VALUE obj, VALUE iv) https://github.com/ruby/ruby/blob/trunk/object.c#L2175 static VALUE rb_obj_ivar_set(VALUE obj, VALUE iv, VALUE val) { - if (!SYMBOL_P(iv) && !rb_is_instance_name(iv)) { + ID id; + + if (SYMBOL_P(iv)) { + id = SYM2ID(iv); + if (!rb_is_instance_id(id)) { + rb_name_error(id, "`%"PRIsVALUE"' is not allowed as an instance variable name", + QUOTE_ID(id)); + } + } + else if (!rb_is_instance_name(iv)) { rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as an instance variable name", QUOTE(iv)); } - return rb_ivar_set(obj, rb_to_id(iv), val); + else { + id = rb_to_id(iv); + } + return rb_ivar_set(obj, id, val); } /* @@ -2273,11 +2296,23 @@ rb_mod_cvar_get(VALUE obj, VALUE iv) https://github.com/ruby/ruby/blob/trunk/object.c#L2296 static VALUE rb_mod_cvar_set(VALUE obj, VALUE iv, VALUE val) { - if (!SYMBOL_P(iv) && !rb_is_class_id(iv)) { + ID id; + + if (SYMBOL_P(iv)) { + id = SYM2ID(iv); + if (!rb_is_class_id(id)) { + rb_name_error(id, "`%"PRIsVALUE"' is not allowed as an class variable name", + QUOTE_ID(id)); + } + } + else if (!rb_is_class_id(iv)) { rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as a class variable name", QUOTE(iv)); } - rb_cvar_set(obj, rb_to_id(iv), val); + else { + id = rb_to_id(iv); + } + rb_cvar_set(obj, id, val); return val; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/