Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip taint tests when perl was built without taint support #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ t/win32.t
xt/author-critic.t
xt/author-pod-coverage.t
xt/author-pod-syntax.t
t/07_taint.pl
t/10_formatting.pl
57 changes: 57 additions & 0 deletions t/07_taint.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/perl -w
use strict;
use Test::More tests => 13;
use Scalar::Util qw(tainted);
use Config;

my $perl_path = $Config{perlpath};

if ($^O ne 'VMS') {
$perl_path .= $Config{_exe}
unless $perl_path =~ m/$Config{_exe}$/i;
}

ok(! tainted($perl_path), '$perl_path is clean');

use_ok("IPC::System::Simple","run","capture");

chdir("t"); # Ignore return, since we may already be in t/

my $taint = $0 . "foo"; # ."foo" to avoid zero length
ok(tainted($taint),"Sanity - executable name is tainted");

my $evil_zero = 1 - (length($taint) / length($taint));

ok(tainted($evil_zero),"Sanity - Evil zero is tainted");
is($evil_zero,"0","Sanity - Evil zero is still zero");

SKIP: {
skip('$ENV{PATH} is clean',2) unless tainted $ENV{PATH};

eval { run("$perl_path exiter.pl 0"); };
like($@,qr{called with tainted environment},"Single-arg, tainted ENV");

eval { run($perl_path, "exiter.pl", 0); };
like($@,qr{called with tainted environment},"Multi-arg, tainted ENV");
}

delete @ENV{qw(PATH IFS CDPATH ENV BASH_ENV PERL5SHELL DCL$PATH)};

eval { run("$perl_path exiter.pl $evil_zero"); };
like($@,qr{called with tainted argument},"Single-arg, tainted data");

eval { run($perl_path, "exiter.pl", $evil_zero); };
like($@,qr{called with tainted argument},"multi-arg, tainted data");

eval { run("$perl_path exiter.pl 0"); };
is($@, "", "Single-arg, clean data and ENV");

eval { run($perl_path, "exiter.pl", 0); };
is($@, "", "Multi-arg, clean data and ENV");

my $data = eval { capture($perl_path, "exiter.pl", 0) };
ok(tainted($data), "Returns of multi-arg capture should be tainted");

$data = eval { capture("$perl_path exiter.pl 0") };
ok(tainted($data), "Returns of single-arg capture should be tainted");

63 changes: 9 additions & 54 deletions t/07_taint.t
Original file line number Diff line number Diff line change
@@ -1,57 +1,12 @@
#!/usr/bin/perl -wT
use strict;
use Test::More tests => 13;
use Scalar::Util qw(tainted);
use Test::More;
use Config;

my $perl_path = $Config{perlpath};

if ($^O ne 'VMS') {
$perl_path .= $Config{_exe}
unless $perl_path =~ m/$Config{_exe}$/i;
if(!$Config{taint_disabled}) {
exec(
$^X, '-T',
(map { "-I$_" } @INC),
't/07_taint.pl'
);
} else {
plan skip_all => 'Test not relevant on a perl built without taint support';
}

ok(! tainted($perl_path), '$perl_path is clean');

use_ok("IPC::System::Simple","run","capture");

chdir("t"); # Ignore return, since we may already be in t/

my $taint = $0 . "foo"; # ."foo" to avoid zero length
ok(tainted($taint),"Sanity - executable name is tainted");

my $evil_zero = 1 - (length($taint) / length($taint));

ok(tainted($evil_zero),"Sanity - Evil zero is tainted");
is($evil_zero,"0","Sanity - Evil zero is still zero");

SKIP: {
skip('$ENV{PATH} is clean',2) unless tainted $ENV{PATH};

eval { run("$perl_path exiter.pl 0"); };
like($@,qr{called with tainted environment},"Single-arg, tainted ENV");

eval { run($perl_path, "exiter.pl", 0); };
like($@,qr{called with tainted environment},"Multi-arg, tainted ENV");
}

delete @ENV{qw(PATH IFS CDPATH ENV BASH_ENV PERL5SHELL DCL$PATH)};

eval { run("$perl_path exiter.pl $evil_zero"); };
like($@,qr{called with tainted argument},"Single-arg, tainted data");

eval { run($perl_path, "exiter.pl", $evil_zero); };
like($@,qr{called with tainted argument},"multi-arg, tainted data");

eval { run("$perl_path exiter.pl 0"); };
is($@, "", "Single-arg, clean data and ENV");

eval { run($perl_path, "exiter.pl", 0); };
is($@, "", "Multi-arg, clean data and ENV");

my $data = eval { capture($perl_path, "exiter.pl", 0) };
ok(tainted($data), "Returns of multi-arg capture should be tainted");

$data = eval { capture("$perl_path exiter.pl 0") };
ok(tainted($data), "Returns of single-arg capture should be tainted");

39 changes: 39 additions & 0 deletions t/10_formatting.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/perl -w
use strict;
use Test::More tests => 5;

use_ok("IPC::System::Simple","run");

# A formatting bug caused ISS to mention its name twice in
# diagnostics. These tests make sure it's fixed.


eval {
run($^X);
};

like($@,qr{^IPC::System::Simple::run called with tainted argument},"Taint pkg only once");

eval {
run(1);
};

like($@,qr{^IPC::System::Simple::run called with tainted environment},"Taint env only once");

# Delete everything in %ENV so we can't get taint errors.

my @keys = keys %ENV;

delete $ENV{$_} foreach @keys;

eval {
run();
};

like($@,qr{^IPC::System::Simple::run called with no arguments},"Package mentioned only once");

eval {
run([0]);
};

like($@,qr{^IPC::System::Simple::run called with no command},"Package mentioned only once");
49 changes: 11 additions & 38 deletions t/10_formatting.t
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
#!/usr/bin/perl -wT
use strict;
use Test::More tests => 5;

use_ok("IPC::System::Simple","run");

# A formatting bug caused ISS to mention its name twice in
# diagnostics. These tests make sure it's fixed.


eval {
run($^X);
};

like($@,qr{^IPC::System::Simple::run called with tainted argument},"Taint pkg only once");

eval {
run(1);
};

like($@,qr{^IPC::System::Simple::run called with tainted environment},"Taint env only once");

# Delete everything in %ENV so we can't get taint errors.

my @keys = keys %ENV;

delete $ENV{$_} foreach @keys;

eval {
run();
};

like($@,qr{^IPC::System::Simple::run called with no arguments},"Package mentioned only once");

eval {
run([0]);
};

like($@,qr{^IPC::System::Simple::run called with no command},"Package mentioned only once");
use Test::More;
use Config;
if(!$Config{taint_disabled}) {
exec(
$^X, '-T',
(map { "-I$_" } @INC),
't/10_formatting.pl'
);
} else {
plan skip_all => 'Test not relevant on a perl built without taint support';
}