3 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "...we will have peace, when you and all your works have perished--and
13 * the works of your dark master to whom you would deliver us. You are a
14 * liar, Saruman, and a corrupter of men's hearts." --Theoden
18 #define PERL_IN_TAINT_C
22 Perl_taint_proper(pTHX_ const char *f, const char *s)
26 #if defined(HAS_SETEUID) && defined(DEBUGGING)
32 DEBUG_u(PerlIO_printf(Perl_debug_log,
33 "%s %d %"UVuf" %"UVuf"\n",
34 s, PL_tainted, uid, euid));
41 DEBUG_u(PerlIO_printf(Perl_debug_log,
42 "%s %d %"IVdf" %"IVdf"\n",
43 s, PL_tainted, uid, euid));
51 if (PL_euid != PL_uid)
52 ug = " while running setuid";
53 else if (PL_egid != PL_gid)
54 ug = " while running setgid";
55 else if (PL_taint_warn)
56 ug = " while running with -t switch";
58 ug = " while running with -T switch";
59 if (PL_unsafe || PL_taint_warn) {
60 if(ckWARN(WARN_TAINT))
61 Perl_warner(aTHX_ packWARN(WARN_TAINT), f, s, ug);
64 Perl_croak(aTHX_ f, s, ug);
75 static char* misc_env[] = {
76 "IFS", /* most shells' inter-field separators */
77 "CDPATH", /* ksh dain bramage #1 */
78 "ENV", /* ksh dain bramage #2 */
79 "BASH_ENV", /* bash dain bramage -- I guess it's contagious */
83 /* Don't bother if there's no *ENV glob */
86 /* If there's no %ENV hash of if it's not magical, croak, because
87 * it probably doesn't reflect the actual environment */
88 if (!GvHV(PL_envgv) || !(SvRMAGICAL(GvHV(PL_envgv))
89 && mg_find((SV*)GvHV(PL_envgv), PERL_MAGIC_env))) {
90 bool was_tainted = PL_tainted;
91 char *name = GvENAME(PL_envgv);
93 if (strEQ(name,"ENV"))
95 taint_proper("%%ENV is aliased to %s%s", "another variable");
97 /* glob alias: report it in the error message */
98 taint_proper("%%ENV is aliased to %%%s%s", name);
99 /* this statement is reached under -t or -U */
100 PL_tainted = was_tainted;
106 char name[10 + TYPE_DIGITS(int)] = "DCL$PATH";
110 (void)sprintf(name,"DCL$PATH;%d", i);
111 svp = hv_fetch(GvHVn(PL_envgv), name, strlen(name), FALSE);
112 if (!svp || *svp == &PL_sv_undef)
114 if (SvTAINTED(*svp)) {
116 taint_proper("Insecure %s%s", "$ENV{DCL$PATH}");
118 if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) {
120 taint_proper("Insecure directory in %s%s", "$ENV{DCL$PATH}");
127 svp = hv_fetch(GvHVn(PL_envgv),"PATH",4,FALSE);
129 if (SvTAINTED(*svp)) {
131 taint_proper("Insecure %s%s", "$ENV{PATH}");
133 if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) {
135 taint_proper("Insecure directory in %s%s", "$ENV{PATH}");
140 /* tainted $TERM is okay if it contains no metachars */
141 svp = hv_fetch(GvHVn(PL_envgv),"TERM",4,FALSE);
142 if (svp && *svp && SvTAINTED(*svp)) {
144 bool was_tainted = PL_tainted;
145 char *t = SvPV(*svp, n_a);
147 PL_tainted = was_tainted;
148 if (t < e && isALNUM(*t))
150 while (t < e && (isALNUM(*t) || strchr("-_.+", *t)))
154 taint_proper("Insecure $ENV{%s}%s", "TERM");
159 for (e = misc_env; *e; e++) {
160 svp = hv_fetch(GvHVn(PL_envgv), *e, strlen(*e), FALSE);
161 if (svp && *svp != &PL_sv_undef && SvTAINTED(*svp)) {
163 taint_proper("Insecure $ENV{%s}%s", *e);