diff options
author | Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> | 2022-11-14 16:44:32 +0000 |
---|---|---|
committer | Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> | 2023-02-10 14:37:25 +0000 |
commit | e51627afd15d704290c8201fdfc02bd7951564f3 (patch) | |
tree | 0f8e9cf574ca6660a774c76f7e54cfaf06e3cab2 /class.c | |
parent | 9bf25cf083493be6ba4df71fd884626369153fce (diff) | |
download | perl-e51627afd15d704290c8201fdfc02bd7951564f3.tar.gz |
Make @ISA a readonly array on class stashes so user code can't fiddle with it and break stuff
Diffstat (limited to 'class.c')
-rw-r--r-- | class.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -379,14 +379,22 @@ apply_class_attribute_isa(pTHX_ HV *stash, SV *value) * You'd think that GvAV() of hv_fetchs() would do it, but no, because it * won't lazily create a proper (magical) GV if one didn't already exist. */ - AV *isa; { SV *isaname = newSVpvf("%" HEKf "::ISA", HvNAME_HEK(stash)); sv_2mortal(isaname); - isa = get_av(SvPV_nolen(isaname), GV_ADD | (SvFLAGS(isaname) & SVf_UTF8)); + AV *isa = get_av(SvPV_nolen(isaname), GV_ADD | (SvFLAGS(isaname) & SVf_UTF8)); + + ENTER; + + /* Temporarily remove the SVf_READONLY flag */ + SAVESETSVFLAGS((SV *)isa, SVf_READONLY|SVf_PROTECT, SVf_READONLY|SVf_PROTECT); + SvREADONLY_off((SV *)isa); + + av_push(isa, newSVsv(value)); + + LEAVE; } - av_push(isa, newSVsv(value)); aux->xhv_class_superclass = (HV *)SvREFCNT_inc(superstash); |