don't allow setting class variable on module that's frozen [Bug #19341]

This commit is contained in:
lukeg 2023-01-14 16:52:29 -05:00 committed by Peter Zhu
parent bf3940a306
commit f66804e6f7
Notes: git 2023-01-19 21:25:41 +00:00
2 changed files with 16 additions and 0 deletions

View File

@ -155,6 +155,21 @@ class TestVariable < Test::Unit::TestCase
end
end
def test_set_class_variable_on_frozen_object
set_cvar = EnvUtil.labeled_class("SetCVar")
set_cvar.class_eval "#{<<~"begin;"}\n#{<<~'end;'}"
begin;
def self.set(val)
@@a = val # inline cache
end
end;
set_cvar.set(1) # fill write cache
set_cvar.freeze
assert_raise(FrozenError) do
set_cvar.set(2) # hit write cache, but should check frozen status
end
end
def test_variable
assert_instance_of(Integer, $$)

View File

@ -3939,6 +3939,7 @@ rb_class_ivar_set(VALUE obj, ID key, VALUE value)
{
RUBY_ASSERT(RB_TYPE_P(obj, T_CLASS) || RB_TYPE_P(obj, T_MODULE));
int found;
rb_check_frozen(obj);
RB_VM_LOCK_ENTER();
{