summaryrefslogtreecommitdiff
path: root/mg.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2014-11-21 08:24:06 -0800
committerFather Chrysostomos <sprout@cpan.org>2014-11-22 04:54:06 -0800
commit199670db6c499615e0f5f53e3c84aa6f11584ff1 (patch)
tree25209d29cddef71a5d6a8865cd738e7cdf5d3c0a /mg.c
parent1b0fd1e8346658cb037cc394f0c428007124b916 (diff)
downloadperl-199670db6c499615e0f5f53e3c84aa6f11584ff1.tar.gz
Protect ${^E_NCODING} from abuse
When read, it is now always undef. When set, it croaks as though read-only except in the encoding package. Hopefully that will dis- suade anyone from depending on it.
Diffstat (limited to 'mg.c')
-rw-r--r--mg.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/mg.c b/mg.c
index f4ee820b93..653800347a 100644
--- a/mg.c
+++ b/mg.c
@@ -858,6 +858,8 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
if (nextchar != '\0') {
if (strEQ(remaining, "NCODING"))
sv_setsv(sv, _get_encoding());
+ else if (strEQ(remaining, "_NCODING"))
+ sv_setsv(sv, NULL);
break;
}
@@ -2648,6 +2650,8 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
/* It may be the shadow variable ${E_NCODING} which has lexical
* scope. See comments at Perl__get_encoding in this file */
if (*(mg->mg_ptr + 1) == '_') {
+ if (CopSTASH(PL_curcop) != get_hv("encoding::",0))
+ Perl_croak_no_modify();
lex = TRUE;
offset++;
}