This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Eliminate Alpha warnings
[perl5.git] / taint.c
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
7 #include "EXTERN.h"
8 #include "perl.h"
9
10 void
11 taint_proper(f, s)
12 const char *f;
13 char *s;
14 {
15     char *ug;
16
17     DEBUG_u(PerlIO_printf(PerlIO_stderr(),
18             "%s %d %d %d\n", s, tainted, uid, euid));
19
20     if (tainted) {
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);
31     }
32 }
33
34 void
35 taint_env()
36 {
37     SV** svp;
38     MAGIC *mg;
39
40 #ifdef VMS
41     int i = 0;
42     char name[14] = "DCL$PATH";
43
44     while (1) {
45         if (i)
46             (void)sprintf(name,"DCL$PATH;%d", i);
47         svp = hv_fetch(GvHVn(envgv), name, strlen(name), FALSE);
48         if (!svp || *svp == &sv_undef)
49             break;
50         if (SvTAINTED(*svp)) {
51             TAINT;
52             taint_proper("Insecure %s%s", "$ENV{DCL$PATH}");
53         }
54         if ((mg = mg_find(*svp, 'e')) && MgTAINTEDDIR(mg)) {
55             TAINT;
56             taint_proper("Insecure directory in %s%s", "$ENV{DCL$PATH}");
57         }
58         i++;
59     }
60 #endif /* VMS */
61
62     svp = hv_fetch(GvHVn(envgv),"PATH",4,FALSE);
63     if (svp && *svp) {
64         if (SvTAINTED(*svp)) {
65             TAINT;
66             taint_proper("Insecure %s%s", "$ENV{PATH}");
67         }
68         if ((mg = mg_find(*svp, 'e')) && MgTAINTEDDIR(mg)) {
69             TAINT;
70             taint_proper("Insecure directory in %s%s", "$ENV{PATH}");
71         }
72     }
73
74     svp = hv_fetch(GvHVn(envgv),"IFS",3,FALSE);
75     if (svp && *svp != &sv_undef && SvTAINTED(*svp)) {
76         TAINT;
77         taint_proper("Insecure %s%s", "$ENV{IFS}");
78     }
79 }