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, (long unsigned int)PL_uid, (long unsigned int)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";
29 ug = " while running with -T switch";
31 Perl_croak(aTHX_ f, s, ug);
32 else if (ckWARN(WARN_TAINT))
33 Perl_warner(aTHX_ WARN_TAINT, f, s, ug);
43 static char* misc_env[] = {
44 "IFS", /* most shells' inter-field separators */
45 "CDPATH", /* ksh dain bramage #1 */
46 "ENV", /* ksh dain bramage #2 */
47 "BASH_ENV", /* bash dain bramage -- I guess it's contagious */
57 char name[10 + TYPE_DIGITS(int)] = "DCL$PATH";
61 (void)sprintf(name,"DCL$PATH;%d", i);
62 svp = hv_fetch(GvHVn(PL_envgv), name, strlen(name), FALSE);
63 if (!svp || *svp == &PL_sv_undef)
65 if (SvTAINTED(*svp)) {
67 taint_proper("Insecure %s%s", "$ENV{DCL$PATH}");
69 if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) {
71 taint_proper("Insecure directory in %s%s", "$ENV{DCL$PATH}");
78 svp = hv_fetch(GvHVn(PL_envgv),"PATH",4,FALSE);
80 if (SvTAINTED(*svp)) {
82 taint_proper("Insecure %s%s", "$ENV{PATH}");
84 if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) {
86 taint_proper("Insecure directory in %s%s", "$ENV{PATH}");
91 /* tainted $TERM is okay if it contains no metachars */
92 svp = hv_fetch(GvHVn(PL_envgv),"TERM",4,FALSE);
93 if (svp && *svp && SvTAINTED(*svp)) {
95 bool was_tainted = PL_tainted;
96 char *t = SvPV(*svp, n_a);
98 PL_tainted = was_tainted;
99 if (t < e && isALNUM(*t))
101 while (t < e && (isALNUM(*t) || *t == '-' || *t == ':'))
105 taint_proper("Insecure $ENV{%s}%s", "TERM");
110 for (e = misc_env; *e; e++) {
111 svp = hv_fetch(GvHVn(PL_envgv), *e, strlen(*e), FALSE);
112 if (svp && *svp != &PL_sv_undef && SvTAINTED(*svp)) {
114 taint_proper("Insecure $ENV{%s}%s", *e);