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 |
79072805 |
11 | taint_proper(f, s) |
71be2cbc |
12 | const char *f; |
79072805 |
13 | char *s; |
14 | { |
bbce6d69 |
15 | char *ug; |
16 | |
1e422769 |
17 | DEBUG_u(PerlIO_printf(PerlIO_stderr(), |
18 | "%s %d %d %d\n", s, tainted, uid, euid)); |
19 | |
bbce6d69 |
20 | if (tainted) { |
bbce6d69 |
21 | if (euid != uid) |
22 | ug = " while running setuid"; |
23 | else if (egid != gid) |
24 | ug = " while running setgid"; |
25 | else |
26 | ug = " while running with -T switch"; |
27 | if (!unsafe) |
28 | croak(f, s, ug); |
29 | else if (dowarn) |
30 | warn(f, s, ug); |
79072805 |
31 | } |
32 | } |
33 | |
34 | void |
35 | taint_env() |
36 | { |
37 | SV** svp; |
7bac28a0 |
38 | MAGIC* mg; |
39 | char** e; |
40 | static char* misc_env[] = { |
41 | "IFS", /* most shells' inter-field separators */ |
42 | "ENV", /* ksh dain bramage #1 */ |
43 | "CDPATH", /* ksh dain bramage #2 */ |
44 | "TERM", /* some termcap libraries' dain bramage */ |
45 | NULL |
46 | }; |
1e422769 |
47 | |
48 | #ifdef VMS |
49 | int i = 0; |
0dc443ab |
50 | char name[10 + TYPE_DIGITS(int)] = "DCL$PATH"; |
1e422769 |
51 | |
52 | while (1) { |
53 | if (i) |
54 | (void)sprintf(name,"DCL$PATH;%d", i); |
55 | svp = hv_fetch(GvHVn(envgv), name, strlen(name), FALSE); |
56 | if (!svp || *svp == &sv_undef) |
57 | break; |
58 | if (SvTAINTED(*svp)) { |
59 | TAINT; |
60 | taint_proper("Insecure %s%s", "$ENV{DCL$PATH}"); |
61 | } |
62 | if ((mg = mg_find(*svp, 'e')) && MgTAINTEDDIR(mg)) { |
63 | TAINT; |
64 | taint_proper("Insecure directory in %s%s", "$ENV{DCL$PATH}"); |
65 | } |
66 | i++; |
67 | } |
68 | #endif /* VMS */ |
79072805 |
69 | |
bbce6d69 |
70 | svp = hv_fetch(GvHVn(envgv),"PATH",4,FALSE); |
1e422769 |
71 | if (svp && *svp) { |
72 | if (SvTAINTED(*svp)) { |
73 | TAINT; |
bbce6d69 |
74 | taint_proper("Insecure %s%s", "$ENV{PATH}"); |
1e422769 |
75 | } |
76 | if ((mg = mg_find(*svp, 'e')) && MgTAINTEDDIR(mg)) { |
77 | TAINT; |
78 | taint_proper("Insecure directory in %s%s", "$ENV{PATH}"); |
79 | } |
79072805 |
80 | } |
79072805 |
81 | |
7bac28a0 |
82 | for (e = misc_env; *e; e++) { |
83 | svp = hv_fetch(GvHVn(envgv), *e, strlen(*e), FALSE); |
84 | if (svp && *svp != &sv_undef && SvTAINTED(*svp)) { |
85 | TAINT; |
86 | taint_proper("Insecure $ENV{%s}%s", *e); |
87 | } |
bbce6d69 |
88 | } |
89 | } |