Commit | Line | Data |
a0d0e21e |
1 | /* |
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 |
5 | */ |
6 | |
463ee0b2 |
7 | #include "EXTERN.h" |
864dbfa3 |
8 | #define PERL_IN_TAINT_C |
463ee0b2 |
9 | #include "perl.h" |
10 | |
11 | void |
dff6d3cd |
12 | Perl_taint_proper(pTHX_ const char *f, const char *s) |
79072805 |
13 | { |
bbce6d69 |
14 | char *ug; |
15 | |
a52cb5f7 |
16 | #ifdef HAS_SETEUID |
fb73857a |
17 | DEBUG_u(PerlIO_printf(Perl_debug_log, |
fe5a182c |
18 | "%s %d %"Uid_t_f" %"Uid_t_f"\n", s, PL_tainted, (Uid_t)PL_uid, (Uid_t)PL_euid)); |
a52cb5f7 |
19 | #endif |
1e422769 |
20 | |
3280af22 |
21 | if (PL_tainted) { |
22c35a8c |
22 | if (!f) |
23 | f = PL_no_security; |
3280af22 |
24 | if (PL_euid != PL_uid) |
bbce6d69 |
25 | ug = " while running setuid"; |
3280af22 |
26 | else if (PL_egid != PL_gid) |
bbce6d69 |
27 | ug = " while running setgid"; |
6537fe72 |
28 | else if (PL_taint_warn) |
29 | ug = " while running with -t switch"; |
30 | else |
bbce6d69 |
31 | ug = " while running with -T switch"; |
6537fe72 |
32 | if (PL_unsafe || PL_taint_warn) { |
33 | if(ckWARN(WARN_TAINT)) |
34 | Perl_warner(aTHX_ WARN_TAINT, f, s, ug); |
35 | } |
36 | else { |
37 | Perl_croak(aTHX_ f, s, ug); |
38 | } |
79072805 |
39 | } |
40 | } |
41 | |
42 | void |
864dbfa3 |
43 | Perl_taint_env(pTHX) |
79072805 |
44 | { |
45 | SV** svp; |
7bac28a0 |
46 | MAGIC* mg; |
47 | char** e; |
48 | static char* misc_env[] = { |
49 | "IFS", /* most shells' inter-field separators */ |
c90c0ff4 |
50 | "CDPATH", /* ksh dain bramage #1 */ |
51 | "ENV", /* ksh dain bramage #2 */ |
52 | "BASH_ENV", /* bash dain bramage -- I guess it's contagious */ |
7bac28a0 |
53 | NULL |
54 | }; |
1e422769 |
55 | |
142393a6 |
56 | if (!PL_envgv) |
57 | return; |
58 | |
1e422769 |
59 | #ifdef VMS |
82f1aded |
60 | { |
1e422769 |
61 | int i = 0; |
0dc443ab |
62 | char name[10 + TYPE_DIGITS(int)] = "DCL$PATH"; |
1e422769 |
63 | |
64 | while (1) { |
65 | if (i) |
66 | (void)sprintf(name,"DCL$PATH;%d", i); |
6b88bc9c |
67 | svp = hv_fetch(GvHVn(PL_envgv), name, strlen(name), FALSE); |
68 | if (!svp || *svp == &PL_sv_undef) |
1e422769 |
69 | break; |
70 | if (SvTAINTED(*svp)) { |
71 | TAINT; |
72 | taint_proper("Insecure %s%s", "$ENV{DCL$PATH}"); |
73 | } |
14befaf4 |
74 | if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) { |
1e422769 |
75 | TAINT; |
76 | taint_proper("Insecure directory in %s%s", "$ENV{DCL$PATH}"); |
77 | } |
78 | i++; |
79 | } |
82f1aded |
80 | } |
1e422769 |
81 | #endif /* VMS */ |
79072805 |
82 | |
3280af22 |
83 | svp = hv_fetch(GvHVn(PL_envgv),"PATH",4,FALSE); |
1e422769 |
84 | if (svp && *svp) { |
85 | if (SvTAINTED(*svp)) { |
86 | TAINT; |
bbce6d69 |
87 | taint_proper("Insecure %s%s", "$ENV{PATH}"); |
1e422769 |
88 | } |
14befaf4 |
89 | if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) { |
1e422769 |
90 | TAINT; |
91 | taint_proper("Insecure directory in %s%s", "$ENV{PATH}"); |
92 | } |
79072805 |
93 | } |
79072805 |
94 | |
c90c0ff4 |
95 | #ifndef VMS |
96 | /* tainted $TERM is okay if it contains no metachars */ |
3280af22 |
97 | svp = hv_fetch(GvHVn(PL_envgv),"TERM",4,FALSE); |
c90c0ff4 |
98 | if (svp && *svp && SvTAINTED(*svp)) { |
2d8e6c8d |
99 | STRLEN n_a; |
3280af22 |
100 | bool was_tainted = PL_tainted; |
2d8e6c8d |
101 | char *t = SvPV(*svp, n_a); |
102 | char *e = t + n_a; |
3280af22 |
103 | PL_tainted = was_tainted; |
c90c0ff4 |
104 | if (t < e && isALNUM(*t)) |
105 | t++; |
106 | while (t < e && (isALNUM(*t) || *t == '-' || *t == ':')) |
107 | t++; |
108 | if (t < e) { |
109 | TAINT; |
110 | taint_proper("Insecure $ENV{%s}%s", "TERM"); |
111 | } |
112 | } |
113 | #endif /* !VMS */ |
114 | |
7bac28a0 |
115 | for (e = misc_env; *e; e++) { |
3280af22 |
116 | svp = hv_fetch(GvHVn(PL_envgv), *e, strlen(*e), FALSE); |
117 | if (svp && *svp != &PL_sv_undef && SvTAINTED(*svp)) { |
7bac28a0 |
118 | TAINT; |
119 | taint_proper("Insecure $ENV{%s}%s", *e); |
120 | } |
bbce6d69 |
121 | } |
122 | } |