source: trunk/third/perl/taint.c @ 14545

Revision 14545, 2.8 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r14544, which included commits to RCS files with non-trunk default branches.
Line 
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#define PERL_IN_TAINT_C
9#include "perl.h"
10
11void
12Perl_taint_proper(pTHX_ const char *f, const char *s)
13{
14    dTHR;       /* just for taint */
15    char *ug;
16
17#ifdef HAS_SETEUID
18    DEBUG_u(PerlIO_printf(Perl_debug_log,
19            "%s %d %"Uid_t_f" %"Uid_t_f"\n", s, PL_tainted, PL_uid, PL_euid));
20#endif
21
22    if (PL_tainted) {
23        if (!f)
24            f = PL_no_security;
25        if (PL_euid != PL_uid)
26            ug = " while running setuid";
27        else if (PL_egid != PL_gid)
28            ug = " while running setgid";
29        else
30            ug = " while running with -T switch";
31        if (!PL_unsafe)
32            Perl_croak(aTHX_ f, s, ug);
33        else if (ckWARN(WARN_TAINT))
34            Perl_warner(aTHX_ WARN_TAINT, f, s, ug);
35    }
36}
37
38void
39Perl_taint_env(pTHX)
40{
41    SV** svp;
42    MAGIC* mg;
43    char** e;
44    static char* misc_env[] = {
45        "IFS",          /* most shells' inter-field separators */
46        "CDPATH",       /* ksh dain bramage #1 */
47        "ENV",          /* ksh dain bramage #2 */
48        "BASH_ENV",     /* bash dain bramage -- I guess it's contagious */
49        NULL
50    };
51
52    if (!PL_envgv)
53        return;
54
55#ifdef VMS
56    {
57    int i = 0;
58    char name[10 + TYPE_DIGITS(int)] = "DCL$PATH";
59
60    while (1) {
61        if (i)
62            (void)sprintf(name,"DCL$PATH;%d", i);
63        svp = hv_fetch(GvHVn(PL_envgv), name, strlen(name), FALSE);
64        if (!svp || *svp == &PL_sv_undef)
65            break;
66        if (SvTAINTED(*svp)) {
67            dTHR;
68            TAINT;
69            taint_proper("Insecure %s%s", "$ENV{DCL$PATH}");
70        }
71        if ((mg = mg_find(*svp, 'e')) && MgTAINTEDDIR(mg)) {
72            dTHR;
73            TAINT;
74            taint_proper("Insecure directory in %s%s", "$ENV{DCL$PATH}");
75        }
76        i++;
77    }
78  }
79#endif /* VMS */
80
81    svp = hv_fetch(GvHVn(PL_envgv),"PATH",4,FALSE);
82    if (svp && *svp) {
83        if (SvTAINTED(*svp)) {
84            dTHR;
85            TAINT;
86            taint_proper("Insecure %s%s", "$ENV{PATH}");
87        }
88        if ((mg = mg_find(*svp, 'e')) && MgTAINTEDDIR(mg)) {
89            dTHR;
90            TAINT;
91            taint_proper("Insecure directory in %s%s", "$ENV{PATH}");
92        }
93    }
94
95#ifndef VMS
96    /* tainted $TERM is okay if it contains no metachars */
97    svp = hv_fetch(GvHVn(PL_envgv),"TERM",4,FALSE);
98    if (svp && *svp && SvTAINTED(*svp)) {
99        dTHR;   /* just for taint */
100        STRLEN n_a;
101        bool was_tainted = PL_tainted;
102        char *t = SvPV(*svp, n_a);
103        char *e = t + n_a;
104        PL_tainted = was_tainted;
105        if (t < e && isALNUM(*t))
106            t++;
107        while (t < e && (isALNUM(*t) || *t == '-' || *t == ':'))
108            t++;
109        if (t < e) {
110            TAINT;
111            taint_proper("Insecure $ENV{%s}%s", "TERM");
112        }
113    }
114#endif /* !VMS */
115
116    for (e = misc_env; *e; e++) {
117        svp = hv_fetch(GvHVn(PL_envgv), *e, strlen(*e), FALSE);
118        if (svp && *svp != &PL_sv_undef && SvTAINTED(*svp)) {
119            dTHR;       /* just for taint */
120            TAINT;
121            taint_proper("Insecure $ENV{%s}%s", *e);
122        }
123    }
124}
Note: See TracBrowser for help on using the repository browser.