You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl-cvs@perl.apache.org by st...@apache.org on 2003/02/04 07:52:16 UTC

cvs commit: modperl-2.0/t/response/TestModperl taint.pm

stas        2003/02/03 22:52:15

  Modified:    .        Changes
               todo     missing_old_features.txt
               src/modules/perl mod_perl.c
               t/modperl .cvsignore
  Added:       t/response/TestModperl taint.pm
  Log:
  perl 5.7.3+ has a built-in ${^TAINT} to test whether running under
  -(T|t). Backport ${^TAINT} for mod_perl running under 5.6.0-5.7.3,
  (what used to be $Apache::__T.  $Apache::__T is available too, but
  deprecated. + tests
  
  Revision  Changes    Path
  1.121     +5 -0      modperl-2.0/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/Changes,v
  retrieving revision 1.120
  retrieving revision 1.121
  diff -u -r1.120 -r1.121
  --- Changes	3 Feb 2003 22:56:19 -0000	1.120
  +++ Changes	4 Feb 2003 06:52:15 -0000	1.121
  @@ -10,6 +10,11 @@
   
   =item 1.99_09-dev
   
  +perl 5.7.3+ has a built-in ${^TAINT} to test whether running under
  +-(T|t). Backport ${^TAINT} for mod_perl running under 5.6.0-5.7.3,
  +(what used to be $Apache::__T.  $Apache::__T is available too, but
  +deprecated. [Stas]
  +
   add PerlChildExitHandler implementation [Stas]
   
   add PerlCleanupHandler implementation + test [Stas]
  
  
  
  1.26      +0 -3      modperl-2.0/todo/missing_old_features.txt
  
  Index: missing_old_features.txt
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/todo/missing_old_features.txt,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- missing_old_features.txt	3 Feb 2003 22:56:19 -0000	1.25
  +++ missing_old_features.txt	4 Feb 2003 06:52:15 -0000	1.26
  @@ -24,9 +24,6 @@
   
   - ... others ...
   
  -- Apache::__T flag which tells whether we run under -T (in 5.8.0 can check
  -  ${^TAINT})
  -
   
   core modules:
   ------------
  
  
  
  1.151     +25 -0     modperl-2.0/src/modules/perl/mod_perl.c
  
  Index: mod_perl.c
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/src/modules/perl/mod_perl.c,v
  retrieving revision 1.150
  retrieving revision 1.151
  diff -u -r1.150 -r1.151
  --- mod_perl.c	3 Feb 2003 22:56:19 -0000	1.150
  +++ mod_perl.c	4 Feb 2003 06:52:15 -0000	1.151
  @@ -101,6 +101,29 @@
       return server_pool;
   }
   
  +static void set_taint_var(PerlInterpreter *perl)
  +{
  +    dTHXa(perl);
  +    GV *gv;
  +
  +/* 5.7.3+ has a built-in special ${^TAINT}, backport it to 5.6.0+ */
  +#if PERL_REVISION == 5 && \
  +    (PERL_VERSION == 6 || (PERL_VERSION == 7 && PERL_SUBVERSION < 3))
  +
  +    gv = gv_fetchpv("\024AINT", GV_ADDMULTI, SVt_IV);
  +    sv_setiv(GvSV(gv), PL_tainting);
  +    SvREADONLY_on(GvSV(gv));
  +#endif /* perl v < 5.7.3 */
  +
  +#ifdef MP_COMPAT_1X
  +    gv = gv_fetchpv("Apache::__T", GV_ADDMULTI, SVt_PV);
  +    sv_setiv(GvSV(gv), PL_tainting);
  +    SvREADONLY_on(GvSV(gv));
  +#endif /* MP_COMPAT_1X */
  +    
  +}
  +
  +
   PerlInterpreter *modperl_startup(server_rec *s, apr_pool_t *p)
   {
       AV *endav;
  @@ -175,6 +198,8 @@
       apr_pool_cleanup_register(server_pool, cdata,
                                 modperl_shutdown, apr_pool_cleanup_null);
   #endif
  +
  +    set_taint_var(perl);
       
       return perl;
   }
  
  
  
  1.12      +1 -0      modperl-2.0/t/modperl/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/t/modperl/.cvsignore,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- .cvsignore	22 Jan 2003 03:19:43 -0000	1.11
  +++ .cvsignore	4 Feb 2003 06:52:15 -0000	1.12
  @@ -11,3 +11,4 @@
   method.t
   setauth.t
   request_rec_tie_api.t
  +taint.t
  \ No newline at end of file
  
  
  
  1.1                  modperl-2.0/t/response/TestModperl/taint.pm
  
  Index: taint.pm
  ===================================================================
  package TestModperl::taint;
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestUtil;
  
  use Apache::RequestIO ();
  use Apache::RequestUtil ();
  
  use Apache::Const -compile => 'OK';
  
  sub handler {
      my $r = shift;
  
      plan $r, tests => 4;
  
      ok t_cmp(1, ${^TAINT}, "\${^TAINT}");
  
      eval { ${^TAINT} = 0 };
      ok t_cmp(qr/read-only/, $@, "\${^TAINT} is read-only");
  
      ok t_cmp(1, $Apache::__T, "\$Apache::__T");
  
      eval { $Apache::__T = 0 };
      ok t_cmp(qr/read-only/, $@, "\$Apache::__T is read-only");
  
      Apache::OK;
  }
  
  1;
  __END__
  
  
  

Re: cvs commit: modperl-2.0/t/response/TestModperl taint.pm

Posted by Stas Bekman <st...@stason.org>.
stas@apache.org wrote:
> stas        2003/02/03 22:52:15
> 
>   Modified:    .        Changes
>                todo     missing_old_features.txt
>                src/modules/perl mod_perl.c
>                t/modperl .cvsignore
>   Added:       t/response/TestModperl taint.pm
>   Log:
>   perl 5.7.3+ has a built-in ${^TAINT} to test whether running under
>   -(T|t). Backport ${^TAINT} for mod_perl running under 5.6.0-5.7.3,
>   (what used to be $Apache::__T.  $Apache::__T is available too, but
>   deprecated. + tests
[...]

As you can see I want us to use ${^TAINT} instead of $Apache::__T, but the 
former was added only in 5.7.3. So I've backported it to 5.6.0+

>   +static void set_taint_var(PerlInterpreter *perl)
>   +{
>   +    dTHXa(perl);
>   +    GV *gv;
>   +
>   +/* 5.7.3+ has a built-in special ${^TAINT}, backport it to 5.6.0+ */
>   +#if PERL_REVISION == 5 && \
>   +    (PERL_VERSION == 6 || (PERL_VERSION == 7 && PERL_SUBVERSION < 3))
>   +
>   +    gv = gv_fetchpv("\024AINT", GV_ADDMULTI, SVt_IV);
>   +    sv_setiv(GvSV(gv), PL_tainting);
>   +    SvREADONLY_on(GvSV(gv));
>   +#endif /* perl v < 5.7.3 */

In 5.7.3+ ${^TAINT} is magic, but I've figured a simple read-only IV will do 
the job for older perls, since we know what PL_tainting is, after starting perl.

>   +#ifdef MP_COMPAT_1X
>   +    gv = gv_fetchpv("Apache::__T", GV_ADDMULTI, SVt_PV);
>   +    sv_setiv(GvSV(gv), PL_tainting);
>   +    SvREADONLY_on(GvSV(gv));
>   +#endif /* MP_COMPAT_1X */
>   +    
>   +}

I'd move the compat $Apache::__T bit to compat.pm, but there is no way to set 
the variable as read-only from core perl. I doubt it's used at all other than 
in Apache::Registry, so may be we drop it?

Lemme know if you have any objections against this move.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org