3 * Copyright (c) 1997-2002, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "...we will have peace, when you and all your works have perished--and
12 * the works of your dark master to whom you would deliver us. You are a
13 * liar, Saruman, and a corrupter of men's hearts." --Theoden
17 #define PERL_IN_TAINT_C
21 Perl_taint_proper(pTHX_ const char *f, const char *s)
25 #if defined(HAS_SETEUID) && defined(DEBUGGING)
31 DEBUG_u(PerlIO_printf(Perl_debug_log,
32 "%s %d %"UVuf" %"UVuf"\n",
33 s, PL_tainted, uid, euid));
40 DEBUG_u(PerlIO_printf(Perl_debug_log,
41 "%s %d %"IVdf" %"IVdf"\n",
42 s, PL_tainted, uid, euid));
50 if (PL_euid != PL_uid)
51 ug = " while running setuid";
52 else if (PL_egid != PL_gid)
53 ug = " while running setgid";
54 else if (PL_taint_warn)
55 ug = " while running with -t switch";
57 ug = " while running with -T switch";
58 if (PL_unsafe || PL_taint_warn) {
59 if(ckWARN(WARN_TAINT))
60 Perl_warner(aTHX_ packWARN(WARN_TAINT), f, s, ug);
63 Perl_croak(aTHX_ f, s, ug);
74 static char* misc_env[] = {
75 "IFS", /* most shells' inter-field separators */
76 "CDPATH", /* ksh dain bramage #1 */
77 "ENV", /* ksh dain bramage #2 */
78 "BASH_ENV", /* bash dain bramage -- I guess it's contagious */
88 char name[10 + TYPE_DIGITS(int)] = "DCL$PATH";
92 (void)sprintf(name,"DCL$PATH;%d", i);
93 svp = hv_fetch(GvHVn(PL_envgv), name, strlen(name), FALSE);
94 if (!svp || *svp == &PL_sv_undef)
96 if (SvTAINTED(*svp)) {
98 taint_proper("Insecure %s%s", "$ENV{DCL$PATH}");
100 if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) {
102 taint_proper("Insecure directory in %s%s", "$ENV{DCL$PATH}");
109 svp = hv_fetch(GvHVn(PL_envgv),"PATH",4,FALSE);
111 if (SvTAINTED(*svp)) {
113 taint_proper("Insecure %s%s", "$ENV{PATH}");
115 if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) {
117 taint_proper("Insecure directory in %s%s", "$ENV{PATH}");
122 /* tainted $TERM is okay if it contains no metachars */
123 svp = hv_fetch(GvHVn(PL_envgv),"TERM",4,FALSE);
124 if (svp && *svp && SvTAINTED(*svp)) {
126 bool was_tainted = PL_tainted;
127 char *t = SvPV(*svp, n_a);
129 PL_tainted = was_tainted;
130 if (t < e && isALNUM(*t))
132 while (t < e && (isALNUM(*t) || strchr("-_.+", *t)))
136 taint_proper("Insecure $ENV{%s}%s", "TERM");
141 for (e = misc_env; *e; e++) {
142 svp = hv_fetch(GvHVn(PL_envgv), *e, strlen(*e), FALSE);
143 if (svp && *svp != &PL_sv_undef && SvTAINTED(*svp)) {
145 taint_proper("Insecure $ENV{%s}%s", *e);