Skip to content
Newer
Older
100644 186 lines (169 sloc) 4.57 KB
d637624 @jhi Sprinkle some copyrights (use the oldest timestamp to
jhi authored Jan 24, 2002
1 /* taint.c
2 *
663f364 Fix up copyright years for files modified in 2007.
Nicholas Clark authored Nov 7, 2007
3 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
4 * 2002, 2003, 2004, 2005, 2006, 2007, by Larry Wall and others
d637624 @jhi Sprinkle some copyrights (use the oldest timestamp to
jhi authored Jan 24, 2002
5 *
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
8 *
9 */
10
a0d0e21 perl 5.000
Larry Wall authored Oct 17, 1994
11 /*
12 * "...we will have peace, when you and all your works have perished--and
13 * the works of your dark master to whom you would deliver us. You are a
14 * liar, Saruman, and a corrupter of men's hearts." --Theoden
15 */
16
166f8a2 Add comment to the top of most .c files explaining their purpose
Dave Mitchell authored Jul 31, 2004
17 /* This file contains a few functions for handling data tainting in Perl
18 */
19
463ee0b perl 5.0 alpha 4
Larry Wall authored Nov 10, 1993
20 #include "EXTERN.h"
864dbfa initial stub implementation of implicit thread/this
Gurusamy Sarathy authored Jun 7, 1999
21 #define PERL_IN_TAINT_C
463ee0b perl 5.0 alpha 4
Larry Wall authored Nov 10, 1993
22 #include "perl.h"
23
24 void
e1c4180 taint.c: consting
Steven Schubiger authored Jan 29, 2008
25 Perl_taint_proper(pTHX_ const char *f, const char *const s)
7907280 perl 5.0 alpha 2
Larry Wall authored Oct 7, 1993
26 {
26e623c @jhi Promote the e/uid to wide enough un/signed integers
jhi authored Dec 24, 2001
27 #if defined(HAS_SETEUID) && defined(DEBUGGING)
97aff36 @jhi sprinkle dVAR
jhi authored Jan 6, 2006
28 dVAR;
26e623c @jhi Promote the e/uid to wide enough un/signed integers
jhi authored Dec 24, 2001
29 # if Uid_t_size == 1
30 {
8772537 @petdance Pre-YAPC consting fun
petdance authored Jun 23, 2005
31 const UV uid = PL_uid;
32 const UV euid = PL_euid;
26e623c @jhi Promote the e/uid to wide enough un/signed integers
jhi authored Dec 24, 2001
33
8772537 @petdance Pre-YAPC consting fun
petdance authored Jun 23, 2005
34 DEBUG_u(PerlIO_printf(Perl_debug_log,
26e623c @jhi Promote the e/uid to wide enough un/signed integers
jhi authored Dec 24, 2001
35 "%s %d %"UVuf" %"UVuf"\n",
36 s, PL_tainted, uid, euid));
37 }
38 # else
39 {
8772537 @petdance Pre-YAPC consting fun
petdance authored Jun 23, 2005
40 const IV uid = PL_uid;
41 const IV euid = PL_euid;
26e623c @jhi Promote the e/uid to wide enough un/signed integers
jhi authored Dec 24, 2001
42
8772537 @petdance Pre-YAPC consting fun
petdance authored Jun 23, 2005
43 DEBUG_u(PerlIO_printf(Perl_debug_log,
26e623c @jhi Promote the e/uid to wide enough un/signed integers
jhi authored Dec 24, 2001
44 "%s %d %"IVdf" %"IVdf"\n",
45 s, PL_tainted, uid, euid));
46 }
47 # endif
a52cb5f @jhi VMS patches from Peter Prymmer.
jhi authored Nov 21, 1999
48 #endif
1e42276 [inseparable changes from match from perl-5.003_90 to perl-5.003_91]
Perl 5 Porters authored Feb 25, 1997
49
3280af2 PL_ prefix to all perlvars, part1
Nick Ing-Simmons authored Jul 18, 1998
50 if (PL_tainted) {
8772537 @petdance Pre-YAPC consting fun
petdance authored Jun 23, 2005
51 const char *ug;
52
22c35a8 phase 1 of somewhat major rearrangement of PERL_OBJECT stuff
Gurusamy Sarathy authored Oct 30, 1998
53 if (!f)
54 f = PL_no_security;
3280af2 PL_ prefix to all perlvars, part1
Nick Ing-Simmons authored Jul 18, 1998
55 if (PL_euid != PL_uid)
bbce6d6 [inseparable changes from patch from perl5.003_08 to perl5.003_09]
Perl 5 Porters authored Nov 26, 1996
56 ug = " while running setuid";
3280af2 PL_ prefix to all perlvars, part1
Nick Ing-Simmons authored Jul 18, 1998
57 else if (PL_egid != PL_gid)
bbce6d6 [inseparable changes from patch from perl5.003_08 to perl5.003_09]
Perl 5 Porters authored Nov 26, 1996
58 ug = " while running setgid";
6537fe7 @schwern -t taint warnings
schwern authored Dec 13, 2001
59 else if (PL_taint_warn)
60 ug = " while running with -t switch";
61 else
bbce6d6 [inseparable changes from patch from perl5.003_08 to perl5.003_09]
Perl 5 Porters authored Nov 26, 1996
62 ug = " while running with -T switch";
6537fe7 @schwern -t taint warnings
schwern authored Dec 13, 2001
63 if (PL_unsafe || PL_taint_warn) {
b7bf404 @rgs Turn taint warnings (-t) into severe warnings, so they're
rgs authored Jan 8, 2007
64 if(ckWARN_d(WARN_TAINT))
9014280 @pmqs more warnings tidyup
pmqs authored Mar 10, 2002
65 Perl_warner(aTHX_ packWARN(WARN_TAINT), f, s, ug);
6537fe7 @schwern -t taint warnings
schwern authored Dec 13, 2001
66 }
67 else {
68 Perl_croak(aTHX_ f, s, ug);
69 }
7907280 perl 5.0 alpha 2
Larry Wall authored Oct 7, 1993
70 }
71 }
72
73 void
864dbfa initial stub implementation of implicit thread/this
Gurusamy Sarathy authored Jun 7, 1999
74 Perl_taint_env(pTHX)
7907280 perl 5.0 alpha 2
Larry Wall authored Oct 7, 1993
75 {
97aff36 @jhi sprinkle dVAR
jhi authored Jan 6, 2006
76 dVAR;
7907280 perl 5.0 alpha 2
Larry Wall authored Oct 7, 1993
77 SV** svp;
7bac28a [inseparable changes from match from perl-5.003_99 to perl-5.003_99a]
Perl 5 Porters authored May 8, 1997
78 MAGIC* mg;
27da23d @jhi Symbian port of Perl
jhi authored Apr 18, 2005
79 const char* const *e;
80 static const char* const misc_env[] = {
7bac28a [inseparable changes from match from perl-5.003_99 to perl-5.003_99a]
Perl 5 Porters authored May 7, 1997
81 "IFS", /* most shells' inter-field separators */
c90c0ff [inseparable changes from match from perl-5.003_99a to perl5.004]
Perl 5 Porters authored May 16, 1997
82 "CDPATH", /* ksh dain bramage #1 */
83 "ENV", /* ksh dain bramage #2 */
84 "BASH_ENV", /* bash dain bramage -- I guess it's contagious */
e62a677 @rgs Check for taintedness of PERL5SHELL on Windows
rgs authored Jul 16, 2006
85 #ifdef WIN32
86 "PERL5SHELL", /* used for system() on Windows */
87 #endif
7bac28a [inseparable changes from match from perl-5.003_99 to perl-5.003_99a]
Perl 5 Porters authored May 7, 1997
88 NULL
89 };
1e42276 [inseparable changes from match from perl-5.003_90 to perl-5.003_91]
Perl 5 Porters authored Feb 25, 1997
90
c038024 @rgs Add a new taint error, "%ENV is aliased to %s".
rgs authored Oct 27, 2003
91 /* Don't bother if there's no *ENV glob */
92 if (!PL_envgv)
142393a @millert "perl -T -P" dumps core on OpenBSD and Linux
millert authored Dec 30, 1998
93 return;
c038024 @rgs Add a new taint error, "%ENV is aliased to %s".
rgs authored Oct 27, 2003
94 /* If there's no %ENV hash of if it's not magical, croak, because
95 * it probably doesn't reflect the actual environment */
96 if (!GvHV(PL_envgv) || !(SvRMAGICAL(GvHV(PL_envgv))
97 && mg_find((SV*)GvHV(PL_envgv), PERL_MAGIC_env))) {
e1ec3a8 @petdance Third consting batch
petdance authored Mar 21, 2005
98 const bool was_tainted = PL_tainted;
8772537 @petdance Pre-YAPC consting fun
petdance authored Jun 23, 2005
99 const char * const name = GvENAME(PL_envgv);
c038024 @rgs Add a new taint error, "%ENV is aliased to %s".
rgs authored Oct 27, 2003
100 PL_tainted = TRUE;
101 if (strEQ(name,"ENV"))
102 /* hash alias */
103 taint_proper("%%ENV is aliased to %s%s", "another variable");
104 else
105 /* glob alias: report it in the error message */
106 taint_proper("%%ENV is aliased to %%%s%s", name);
107 /* this statement is reached under -t or -U */
108 PL_tainted = was_tainted;
109 }
142393a @millert "perl -T -P" dumps core on OpenBSD and Linux
millert authored Dec 30, 1998
110
1e42276 [inseparable changes from match from perl-5.003_90 to perl-5.003_91]
Perl 5 Porters authored Feb 25, 1997
111 #ifdef VMS
82f1ade taint.c fix for VMS
Hans Mulder authored Jan 5, 1999
112 {
1e42276 [inseparable changes from match from perl-5.003_90 to perl-5.003_91]
Perl 5 Porters authored Feb 25, 1997
113 int i = 0;
0dc443a Fix possible buffer overflow under VMS
Chip Salzenberg authored Mar 1, 1997
114 char name[10 + TYPE_DIGITS(int)] = "DCL$PATH";
86c1194 Use the return value from sprintf().
Nicholas Clark authored Nov 4, 2005
115 STRLEN len = 8; /* strlen(name) */
1e42276 [inseparable changes from match from perl-5.003_90 to perl-5.003_91]
Perl 5 Porters authored Feb 25, 1997
116
117 while (1) {
118 if (i)
86c1194 Use the return value from sprintf().
Nicholas Clark authored Nov 4, 2005
119 len = my_sprintf(name,"DCL$PATH;%d", i);
120 svp = hv_fetch(GvHVn(PL_envgv), name, len, FALSE);
6b88bc9 complete s/foo/PL_foo/ changes (all escaped cases identified with
Gurusamy Sarathy authored Jul 20, 1998
121 if (!svp || *svp == &PL_sv_undef)
1e42276 [inseparable changes from match from perl-5.003_90 to perl-5.003_91]
Perl 5 Porters authored Feb 25, 1997
122 break;
123 if (SvTAINTED(*svp)) {
124 TAINT;
125 taint_proper("Insecure %s%s", "$ENV{DCL$PATH}");
126 }
c038024 @rgs Add a new taint error, "%ENV is aliased to %s".
rgs authored Oct 27, 2003
127 if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) {
1e42276 [inseparable changes from match from perl-5.003_90 to perl-5.003_91]
Perl 5 Porters authored Feb 25, 1997
128 TAINT;
129 taint_proper("Insecure directory in %s%s", "$ENV{DCL$PATH}");
130 }
131 i++;
132 }
82f1ade taint.c fix for VMS
Hans Mulder authored Jan 5, 1999
133 }
1e42276 [inseparable changes from match from perl-5.003_90 to perl-5.003_91]
Perl 5 Porters authored Feb 25, 1997
134 #endif /* VMS */
7907280 perl 5.0 alpha 2
Larry Wall authored Oct 7, 1993
135
a4fc7ab @petdance hv_fetchs() support
petdance authored Jan 6, 2006
136 svp = hv_fetchs(GvHVn(PL_envgv),"PATH",FALSE);
1e42276 [inseparable changes from match from perl-5.003_90 to perl-5.003_91]
Perl 5 Porters authored Feb 25, 1997
137 if (svp && *svp) {
138 if (SvTAINTED(*svp)) {
139 TAINT;
bbce6d6 [inseparable changes from patch from perl5.003_08 to perl5.003_09]
Perl 5 Porters authored Nov 26, 1996
140 taint_proper("Insecure %s%s", "$ENV{PATH}");
1e42276 [inseparable changes from match from perl-5.003_90 to perl-5.003_91]
Perl 5 Porters authored Feb 25, 1997
141 }
c038024 @rgs Add a new taint error, "%ENV is aliased to %s".
rgs authored Oct 27, 2003
142 if ((mg = mg_find(*svp, PERL_MAGIC_envelem)) && MgTAINTEDDIR(mg)) {
1e42276 [inseparable changes from match from perl-5.003_90 to perl-5.003_91]
Perl 5 Porters authored Feb 25, 1997
143 TAINT;
144 taint_proper("Insecure directory in %s%s", "$ENV{PATH}");
145 }
7907280 perl 5.0 alpha 2
Larry Wall authored Oct 7, 1993
146 }
147
c90c0ff [inseparable changes from match from perl-5.003_99a to perl5.004]
Perl 5 Porters authored May 15, 1997
148 #ifndef VMS
149 /* tainted $TERM is okay if it contains no metachars */
a4fc7ab @petdance hv_fetchs() support
petdance authored Jan 6, 2006
150 svp = hv_fetchs(GvHVn(PL_envgv),"TERM",FALSE);
c90c0ff [inseparable changes from match from perl-5.003_99a to perl5.004]
Perl 5 Porters authored May 15, 1997
151 if (svp && *svp && SvTAINTED(*svp)) {
8b6b16e Nuke some more n_a, and convert S_gv_ename from char * to const char *
Nicholas Clark authored Jun 8, 2005
152 STRLEN len;
73d840c @petdance Consting part 4
petdance authored Mar 25, 2005
153 const bool was_tainted = PL_tainted;
cfd0369 More SvPV consting. And other related drive-by refactoring.
Nicholas Clark authored Jun 10, 2005
154 const char *t = SvPV_const(*svp, len);
8772537 @petdance Pre-YAPC consting fun
petdance authored Jun 23, 2005
155 const char * const e = t + len;
3280af2 PL_ prefix to all perlvars, part1
Nick Ing-Simmons authored Jul 18, 1998
156 PL_tainted = was_tainted;
c90c0ff [inseparable changes from match from perl-5.003_99a to perl5.004]
Perl 5 Porters authored May 15, 1997
157 if (t < e && isALNUM(*t))
158 t++;
d085cc7 @rgs Change the set of characters that are considered to be
rgs authored Dec 8, 2002
159 while (t < e && (isALNUM(*t) || strchr("-_.+", *t)))
c90c0ff [inseparable changes from match from perl-5.003_99a to perl5.004]
Perl 5 Porters authored May 15, 1997
160 t++;
161 if (t < e) {
162 TAINT;
163 taint_proper("Insecure $ENV{%s}%s", "TERM");
164 }
165 }
166 #endif /* !VMS */
167
7bac28a [inseparable changes from match from perl-5.003_99 to perl-5.003_99a]
Perl 5 Porters authored May 7, 1997
168 for (e = misc_env; *e; e++) {
0bd4880 @petdance More consting, and putting stuff in embed.fnc
petdance authored Dec 5, 2005
169 SV * const * const svp = hv_fetch(GvHVn(PL_envgv), *e, strlen(*e), FALSE);
3280af2 PL_ prefix to all perlvars, part1
Nick Ing-Simmons authored Jul 18, 1998
170 if (svp && *svp != &PL_sv_undef && SvTAINTED(*svp)) {
7bac28a [inseparable changes from match from perl-5.003_99 to perl-5.003_99a]
Perl 5 Porters authored May 7, 1997
171 TAINT;
172 taint_proper("Insecure $ENV{%s}%s", *e);
173 }
bbce6d6 [inseparable changes from patch from perl5.003_08 to perl5.003_09]
Perl 5 Porters authored Nov 26, 1996
174 }
175 }
66610fd @rgs Add editor boilerplates to all C files
rgs authored May 10, 2005
176
177 /*
178 * Local variables:
179 * c-indentation-style: bsd
180 * c-basic-offset: 4
181 * indent-tabs-mode: t
182 * End:
183 *
37442d5 @rgs Include vim/emacs modelines in generated files to open them
rgs authored May 11, 2005
184 * ex: set ts=8 sts=4 sw=4 noet:
185 */
Something went wrong with that request. Please try again.