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)
14 dTHR; /* just for taint */
17 DEBUG_u(PerlIO_printf(Perl_debug_log,
18 "%s %d %"Uid_t_f" %"Uid_t_f"\n", s, PL_tainted, PL_uid, PL_euid));
23 if (PL_euid != PL_uid)
24 ug = " while running setuid";
25 else if (PL_egid != PL_gid)
26 ug = " while running setgid";
28 ug = " while running with -T switch";
30 Perl_croak(aTHX_ f, s, ug);
31 else if (ckWARN(WARN_TAINT))
32 Perl_warner(aTHX_ WARN_TAINT, f, s, ug);
42 static char* misc_env[] = {
43 "IFS", /* most shells' inter-field separators */
44 "CDPATH", /* ksh dain bramage #1 */
45 "ENV", /* ksh dain bramage #2 */
46 "BASH_ENV", /* bash dain bramage -- I guess it's contagious */
56 char name[10 + TYPE_DIGITS(int)] = "DCL$PATH";
60 (void)sprintf(name,"DCL$PATH;%d", i);
61 svp = hv_fetch(GvHVn(PL_envgv), name, strlen(name), FALSE);
62 if (!svp || *svp == &PL_sv_undef)
64 if (SvTAINTED(*svp)) {
67 taint_proper("Insecure %s%s", "$ENV{DCL$PATH}");
69 if ((mg = mg_find(*svp, 'e')) && MgTAINTEDDIR(mg)) {
72 taint_proper("Insecure directory in %s%s", "$ENV{DCL$PATH}");
79 svp = hv_fetch(GvHVn(PL_envgv),"PATH",4,FALSE);
81 if (SvTAINTED(*svp)) {
84 taint_proper("Insecure %s%s", "$ENV{PATH}");
86 if ((mg = mg_find(*svp, 'e')) && MgTAINTEDDIR(mg)) {
89 taint_proper("Insecure directory in %s%s", "$ENV{PATH}");
94 /* tainted $TERM is okay if it contains no metachars */
95 svp = hv_fetch(GvHVn(PL_envgv),"TERM",4,FALSE);
96 if (svp && *svp && SvTAINTED(*svp)) {
97 dTHR; /* just for taint */
99 bool was_tainted = PL_tainted;
100 char *t = SvPV(*svp, n_a);
102 PL_tainted = was_tainted;
103 if (t < e && isALNUM(*t))
105 while (t < e && (isALNUM(*t) || *t == '-' || *t == ':'))
109 taint_proper("Insecure $ENV{%s}%s", "TERM");
114 for (e = misc_env; *e; e++) {
115 svp = hv_fetch(GvHVn(PL_envgv), *e, strlen(*e), FALSE);
116 if (svp && *svp != &PL_sv_undef && SvTAINTED(*svp)) {
117 dTHR; /* just for taint */
119 taint_proper("Insecure $ENV{%s}%s", *e);