Commit | Line | Data |
---|---|---|
a0d0e21e LW |
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 LW |
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, |
1e422769 | 17 | "%s %d %d %d\n", s, tainted, uid, euid)); |
18 | ||
bbce6d69 | 19 | if (tainted) { |
bbce6d69 | 20 | if (euid != uid) |
21 | ug = " while running setuid"; | |
22 | else if (egid != gid) | |
23 | ug = " while running setgid"; | |
24 | else | |
25 | ug = " while running with -T switch"; | |
26 | if (!unsafe) | |
27 | croak(f, s, ug); | |
28 | else if (dowarn) | |
29 | warn(f, s, ug); | |
79072805 LW |
30 | } |
31 | } | |
32 | ||
33 | void | |
8ac85365 | 34 | taint_env(void) |
79072805 LW |
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); | |
54 | svp = hv_fetch(GvHVn(envgv), name, strlen(name), FALSE); | |
55 | if (!svp || *svp == &sv_undef) | |
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 | |
bbce6d69 | 71 | svp = hv_fetch(GvHVn(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 */ | |
87 | svp = hv_fetch(GvHVn(envgv),"TERM",4,FALSE); | |
88 | if (svp && *svp && SvTAINTED(*svp)) { | |
aeea060c | 89 | dTHR; /* just for taint */ |
c90c0ff4 | 90 | bool was_tainted = tainted; |
91 | char *t = SvPV(*svp, na); | |
92 | char *e = t + na; | |
93 | tainted = was_tainted; | |
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++) { |
106 | svp = hv_fetch(GvHVn(envgv), *e, strlen(*e), FALSE); | |
107 | if (svp && *svp != &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 | } |