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