2 * "...we will have peace, when you and all your works have perished--and
3 * the works of your dark master to whom you would deliver us. You are a
4 * liar, Saruman, and a corrupter of men's hearts." --Theoden
8 #define PERL_IN_TAINT_C
12 Perl_taint_proper(pTHX_ const char *f, const char *s)
16 #if defined(HAS_SETEUID) && defined(DEBUGGING)
22 DEBUG_u(PerlIO_printf(Perl_debug_log,
23 "%s %d %"UVuf" %"UVuf"\n",
24 s, PL_tainted, uid, euid));
31 DEBUG_u(PerlIO_printf(Perl_debug_log,
32 "%s %d %"IVdf" %"IVdf"\n",
33 s, PL_tainted, uid, euid));
41 if (PL_euid != PL_uid)
42 ug = " while running setuid";
43 else if (PL_egid != PL_gid)
44 ug = " while running setgid";
45 else if (PL_taint_warn)
46 ug = " while running with -t switch";
48 ug = " while running with -T switch";
49 if (PL_unsafe || PL_taint_warn) {
50 if(ckWARN(WARN_TAINT))
51 Perl_warner(aTHX_ WARN_TAINT, f, s, ug);
54 Perl_croak(aTHX_ f, s, ug);
65 static char* misc_env[] = {
66 "IFS", /* most shells' inter-field separators */
67 "CDPATH", /* ksh dain bramage #1 */
68 "ENV", /* ksh dain bramage #2 */
69 "BASH_ENV", /* bash dain bramage -- I guess it's contagious */
79 char name[10 + TYPE_DIGITS(int)] = "DCL$PATH";
83 (void)sprintf(name,"DCL$PATH;%d", i);
84 svp = hv_fetch(GvHVn(PL_envgv), name, strlen(name), FALSE);
85 if (!svp || *svp == &PL_sv_undef)
87 if (SvTAINTED(*svp)) {
89 taint_proper("Insecure %s%s", "$ENV{DCL$PATH}");
91 if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) {
93 taint_proper("Insecure directory in %s%s", "$ENV{DCL$PATH}");
100 svp = hv_fetch(GvHVn(PL_envgv),"PATH",4,FALSE);
102 if (SvTAINTED(*svp)) {
104 taint_proper("Insecure %s%s", "$ENV{PATH}");
106 if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) {
108 taint_proper("Insecure directory in %s%s", "$ENV{PATH}");
113 /* tainted $TERM is okay if it contains no metachars */
114 svp = hv_fetch(GvHVn(PL_envgv),"TERM",4,FALSE);
115 if (svp && *svp && SvTAINTED(*svp)) {
117 bool was_tainted = PL_tainted;
118 char *t = SvPV(*svp, n_a);
120 PL_tainted = was_tainted;
121 if (t < e && isALNUM(*t))
123 while (t < e && (isALNUM(*t) || *t == '-' || *t == ':'))
127 taint_proper("Insecure $ENV{%s}%s", "TERM");
132 for (e = misc_env; *e; e++) {
133 svp = hv_fetch(GvHVn(PL_envgv), *e, strlen(*e), FALSE);
134 if (svp && *svp != &PL_sv_undef && SvTAINTED(*svp)) {
136 taint_proper("Insecure $ENV{%s}%s", *e);