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, char *s)
14 dTHR; /* just for taint */
18 DEBUG_u(PerlIO_printf(Perl_debug_log,
19 "%s %d %" PERL_PRId64 " %" PERL_PRId64 "\n", s, PL_tainted, (IV)PL_uid, (IV)PL_euid));
21 DEBUG_u(PerlIO_printf(Perl_debug_log,
22 "%s %d %lu %lu\n", s, PL_tainted, (unsigned long)PL_uid, (unsigned long)PL_euid));
28 if (PL_euid != PL_uid)
29 ug = " while running setuid";
30 else if (PL_egid != PL_gid)
31 ug = " while running setgid";
33 ug = " while running with -T switch";
35 Perl_croak(aTHX_ f, s, ug);
36 else if (ckWARN(WARN_TAINT))
37 Perl_warner(aTHX_ WARN_TAINT, f, s, ug);
47 static char* misc_env[] = {
48 "IFS", /* most shells' inter-field separators */
49 "CDPATH", /* ksh dain bramage #1 */
50 "ENV", /* ksh dain bramage #2 */
51 "BASH_ENV", /* bash dain bramage -- I guess it's contagious */
61 char name[10 + TYPE_DIGITS(int)] = "DCL$PATH";
65 (void)sprintf(name,"DCL$PATH;%d", i);
66 svp = hv_fetch(GvHVn(PL_envgv), name, strlen(name), FALSE);
67 if (!svp || *svp == &PL_sv_undef)
69 if (SvTAINTED(*svp)) {
72 taint_proper("Insecure %s%s", "$ENV{DCL$PATH}");
74 if ((mg = mg_find(*svp, 'e')) && MgTAINTEDDIR(mg)) {
77 taint_proper("Insecure directory in %s%s", "$ENV{DCL$PATH}");
84 svp = hv_fetch(GvHVn(PL_envgv),"PATH",4,FALSE);
86 if (SvTAINTED(*svp)) {
89 taint_proper("Insecure %s%s", "$ENV{PATH}");
91 if ((mg = mg_find(*svp, 'e')) && MgTAINTEDDIR(mg)) {
94 taint_proper("Insecure directory in %s%s", "$ENV{PATH}");
99 /* tainted $TERM is okay if it contains no metachars */
100 svp = hv_fetch(GvHVn(PL_envgv),"TERM",4,FALSE);
101 if (svp && *svp && SvTAINTED(*svp)) {
102 dTHR; /* just for taint */
104 bool was_tainted = PL_tainted;
105 char *t = SvPV(*svp, n_a);
107 PL_tainted = was_tainted;
108 if (t < e && isALNUM(*t))
110 while (t < e && (isALNUM(*t) || *t == '-' || *t == ':'))
114 taint_proper("Insecure $ENV{%s}%s", "TERM");
119 for (e = misc_env; *e; e++) {
120 svp = hv_fetch(GvHVn(PL_envgv), *e, strlen(*e), FALSE);
121 if (svp && *svp != &PL_sv_undef && SvTAINTED(*svp)) {
122 dTHR; /* just for taint */
124 taint_proper("Insecure $ENV{%s}%s", *e);