From e100fcbdd1e81c23e3b4c87964aff210232903a8 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Wed, 10 Jun 2020 18:44:52 -0400 Subject: Prohibit setting class variable on frozen module through inheritance Setting class varibles goes through the ancestor list which can contain iclasses. Iclasses share a lot of information with the module they are made from, but not the frozen status. Check the frozen status of the module instead of the iclass. --- variable.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'variable.c') diff --git a/variable.c b/variable.c index ebf23fab67..0d8a424438 100644 --- a/variable.c +++ b/variable.c @@ -3143,6 +3143,9 @@ rb_cvar_set(VALUE klass, ID id, VALUE val) target = tmp; } + if (RB_TYPE_P(target, T_ICLASS)) { + target = RBASIC(target)->klass; + } check_before_mod_set(target, id, val, "class variable"); if (!RCLASS_IV_TBL(target)) { RCLASS_IV_TBL(target) = st_init_numtable(); -- cgit v1.2.3