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)
17 DEBUG_u(PerlIO_printf(Perl_debug_log,
18 "%s %d %"Uid_t_f" %"Uid_t_f"\n", s, PL_tainted, (Uid_t)PL_uid, (Uid_t)PL_euid));
24 if (PL_euid != PL_uid)
25 ug = " while running setuid";
26 else if (PL_egid != PL_gid)
27 ug = " while running setgid";
28 else if (PL_taint_warn)
29 ug = " while running with -t switch";
31 ug = " while running with -T switch";
32 if (PL_unsafe || PL_taint_warn) {
33 if(ckWARN(WARN_TAINT))
34 Perl_warner(aTHX_ WARN_TAINT, f, s, ug);
37 Perl_croak(aTHX_ f, s, ug);
48 static char* misc_env[] = {
49 "IFS", /* most shells' inter-field separators */
50 "CDPATH", /* ksh dain bramage #1 */
51 "ENV", /* ksh dain bramage #2 */
52 "BASH_ENV", /* bash dain bramage -- I guess it's contagious */
62 char name[10 + TYPE_DIGITS(int)] = "DCL$PATH";
66 (void)sprintf(name,"DCL$PATH;%d", i);
67 svp = hv_fetch(GvHVn(PL_envgv), name, strlen(name), FALSE);
68 if (!svp || *svp == &PL_sv_undef)
70 if (SvTAINTED(*svp)) {
72 taint_proper("Insecure %s%s", "$ENV{DCL$PATH}");
74 if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) {
76 taint_proper("Insecure directory in %s%s", "$ENV{DCL$PATH}");
83 svp = hv_fetch(GvHVn(PL_envgv),"PATH",4,FALSE);
85 if (SvTAINTED(*svp)) {
87 taint_proper("Insecure %s%s", "$ENV{PATH}");
89 if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) {
91 taint_proper("Insecure directory in %s%s", "$ENV{PATH}");
96 /* tainted $TERM is okay if it contains no metachars */
97 svp = hv_fetch(GvHVn(PL_envgv),"TERM",4,FALSE);
98 if (svp && *svp && SvTAINTED(*svp)) {
100 bool was_tainted = PL_tainted;
101 char *t = SvPV(*svp, n_a);
103 PL_tainted = was_tainted;
104 if (t < e && isALNUM(*t))
106 while (t < e && (isALNUM(*t) || *t == '-' || *t == ':'))
110 taint_proper("Insecure $ENV{%s}%s", "TERM");
115 for (e = misc_env; *e; e++) {
116 svp = hv_fetch(GvHVn(PL_envgv), *e, strlen(*e), FALSE);
117 if (svp && *svp != &PL_sv_undef && SvTAINTED(*svp)) {
119 taint_proper("Insecure $ENV{%s}%s", *e);