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