Detecting taint mode

Andy Armstrong andy at hexten.net
Sun Feb 25 21:05:12 GMT 2007


On 25 Feb 2007, at 20:55, Andy Armstrong wrote:
> Looks evil but presumably works:
>
> sub is_tainted2 { local $^W = 0; local $@; eval { kill 0 * $_[0] };  
> $@ =~ /^Insecure/ }
>
> From:
>
> http://search.cpan.org/src/RHANDOM/Taint-Runtime-0.02/lib/Taint/ 
> Runtime.pm

But that isn't what you asked... This is better:


sub _taint_is_on
{
     if ( $] >= 5.008 )
     {
         # We have to eval a string because this variable name causes
         # earlier Perls to not compile at all.
         return eval '${^TAINT}' ? 1 : 0;
     }
     else
     {
         local $^W;
         eval { "+$0$^X" && eval 1 };
         return $@ ? 1 : 0;
     }
}

From:

http://search.cpan.org/src/DROLSKY/HTML-Mason-1.35/lib/HTML/Mason/ 
Tools.pm

-- 
Andy Armstrong, hexten.net



More information about the london.pm mailing list