summaryrefslogtreecommitdiff
path: root/op.c
diff options
context:
space:
mode:
authorTony Cook <tony@develop-help.com>2020-06-08 10:13:35 +1000
committerTony Cook <tony@develop-help.com>2021-01-04 11:28:58 +1100
commit0f2beabb08039ae97dbc9dc54dff894c14b6e38b (patch)
treea0fc936631642074e16d9c1e09356c15065f9966 /op.c
parentded7c7ec0c875ea7bd53811b9db312f3b2e85a95 (diff)
downloadperl-0f2beabb08039ae97dbc9dc54dff894c14b6e38b.tar.gz
add a bareword_filehandles feature, which is enabled by default
This disables use of bareword filehandles except for the built-in handles
Diffstat (limited to 'op.c')
-rw-r--r--op.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/op.c b/op.c
index dce844d297..889a032736 100644
--- a/op.c
+++ b/op.c
@@ -724,6 +724,21 @@ S_no_bareword_allowed(pTHX_ OP *o)
o->op_private &= ~OPpCONST_STRICT; /* prevent warning twice about the same OP */
}
+void
+Perl_no_bareword_filehandle(pTHX_ const char *fhname) {
+ PERL_ARGS_ASSERT_NO_BAREWORD_FILEHANDLE;
+
+ if (strNE(fhname, "STDERR")
+ && strNE(fhname, "STDOUT")
+ && strNE(fhname, "STDIN")
+ && strNE(fhname, "_")
+ && strNE(fhname, "ARGV")
+ && strNE(fhname, "ARGVOUT")
+ && strNE(fhname, "DATA")) {
+ qerror(Perl_mess(aTHX_ "Bareword filehandle \"%s\" not allowed under 'no feature \"bareword_filehandles\"'", fhname));
+ }
+}
+
/* "register" allocation */
PADOFFSET
@@ -13090,6 +13105,11 @@ Perl_ck_fun(pTHX_ OP *o)
{
OP * const newop = newGVOP(OP_GV, 0,
gv_fetchsv(((SVOP*)kid)->op_sv, GV_ADD, SVt_PVIO));
+ /* a first argument is handled by toke.c, ideally we'd
+ just check here but several ops don't use ck_fun() */
+ if (!FEATURE_BAREWORD_FILEHANDLES_IS_ENABLED && numargs > 1) {
+ no_bareword_filehandle(SvPVX(cSVOPx_sv((SVOP*)kid)));
+ }
/* replace kid with newop in chain */
op_sibling_splice(o, prev_kid, 1, newop);
op_free(kid);
@@ -15159,6 +15179,9 @@ Perl_ck_trunc(pTHX_ OP *o)
{
o->op_flags |= OPf_SPECIAL;
kid->op_private &= ~OPpCONST_STRICT;
+ if (!FEATURE_BAREWORD_FILEHANDLES_IS_ENABLED) {
+ no_bareword_filehandle(SvPVX(cSVOPx_sv(kid)));
+ }
}
}
return ck_fun(o);