From 76a929a7fca3c84630574e4daa9dab7a96b04fc8 Mon Sep 17 00:00:00 2001 From: ko1 Date: Wed, 9 Jul 2014 06:14:41 +0000 Subject: * parse.y: change Symbol <-> ID relationship to avoid exposing IDs from collectable symbols. [Bug #10014] Now, rb_check_id() returns 0 if corresponding symbol is pinned dynamic symbol. There is remaining intern_cstr_without_pindown(), it can return IDs from collectable symbols. We must be careful to use it (only used in parse.y). I think it should be removed if it does not have impact for performance. * parse.y: add: * STATIC_SYM2ID() * STATIC_ID2SYM() rename: * rb_pin_dynamic_symbol() -> dsymbol_pindown() * internal.h: remove: * rb_check_id_without_pindown() * rb_sym2id_without_pindown() add: * rb_check_symbol() * rb_check_symbol_cstr() * load.c: use rb_check_id() or rb_check_id_cstr(). * object.c: ditto. * struct.c: ditto. * thread.c: ditto. * vm_method.c: ditto. * string.c (sym_find): use only rb_check_symbol(). * sprintf.c (rb_str_format): use rb_check_symbol_cstr(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- sprintf.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'sprintf.c') diff --git a/sprintf.c b/sprintf.c index 6a2ee402aa..3d2d6db4b6 100644 --- a/sprintf.c +++ b/sprintf.c @@ -506,7 +506,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) for (; p < end; p++) { const char *t; int n; - ID id = 0; + VALUE sym = Qnil; for (t = p; t < end && *t != '%'; t++) ; PUSH(p, t - p); @@ -601,16 +601,16 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) } #endif len = (int)(p - start + 1); /* including parenthesis */ - if (id) { + if (sym != Qnil) { rb_enc_raise(enc, rb_eArgError, "named%.*s after <%s>", - len, start, rb_id2name(id)); + len, start, RSTRING_PTR(rb_sym2str(sym))); } CHECKNAMEARG(start, len, enc); get_hash(&hash, argc, argv); - id = rb_check_id_cstr_without_pindown(start + 1, - len - 2 /* without parenthesis */, - enc); - if (id) nextvalue = rb_hash_lookup2(hash, ID2SYM(id), Qundef); + sym = rb_check_symbol_cstr(start + 1, + len - 2 /* without parenthesis */, + enc); + if (sym != Qnil) nextvalue = rb_hash_lookup2(hash, sym, Qundef); if (nextvalue == Qundef) { rb_enc_raise(enc, rb_eKeyError, "key%.*s not found", len, start); } -- cgit v1.2.3