K
kj
For testing purposes I would like to be able to intentionally taint
a variable. What's the easiest way to do this?
TIA!
~K
P.S. I tried mucking around with the function SvTAINT and Inline::C,
but my test script crashes when I run it under -T. Code below;
completely untested.
#!/usr/bin/perl
BEGIN {
@INC = map { /(.*)/; $1 } @INC;
}
# the following Inline configuration sidesteps an "insecure
# dependency" fatal error when run under -T
use Inline (Config =>
DIRECTORY => '/home/jones/tmp/_Inline');
use Inline C;
use strict;
use warnings FATAL => 'all';
my $v = 42;
print +(is_tainted($v) ? 1 : 0), "\n";
taint($v);
print +(is_tainted($v) ? 1 : 0), "\n";
sub is_tainted {
# adapted from code in Programming Perl 3d ed, p. 561
my $arg = shift;
my $empty = do {
no warnings 'uninitialized';
substr( $arg, 0, 0 );
};
local $@;
eval { eval "# $empty" };
return length( $@ ) != 0;
}
__END__
__C__
void taint(SV *sv) {
SvTAINT(sv);
TAINT;
return;
}
a variable. What's the easiest way to do this?
TIA!
~K
P.S. I tried mucking around with the function SvTAINT and Inline::C,
but my test script crashes when I run it under -T. Code below;
completely untested.
#!/usr/bin/perl
BEGIN {
@INC = map { /(.*)/; $1 } @INC;
}
# the following Inline configuration sidesteps an "insecure
# dependency" fatal error when run under -T
use Inline (Config =>
DIRECTORY => '/home/jones/tmp/_Inline');
use Inline C;
use strict;
use warnings FATAL => 'all';
my $v = 42;
print +(is_tainted($v) ? 1 : 0), "\n";
taint($v);
print +(is_tainted($v) ? 1 : 0), "\n";
sub is_tainted {
# adapted from code in Programming Perl 3d ed, p. 561
my $arg = shift;
my $empty = do {
no warnings 'uninitialized';
substr( $arg, 0, 0 );
};
local $@;
eval { eval "# $empty" };
return length( $@ ) != 0;
}
__END__
__C__
void taint(SV *sv) {
SvTAINT(sv);
TAINT;
return;
}