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