Created
March 6, 2011 15:51
-
-
Save dotandimet/857366 to your computer and use it in GitHub Desktop.
test for Mojo::Loader arbitrary code execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use warnings; | |
use strict; | |
# Mojo::Loader executes arbitray code - via vti | |
# perl -MMojo::Loader -e 'Mojo::Loader->load(qq{Mojo::Loader;print "nice feature!"})' | |
# http://twitter.com/#!/vtivti/status/44408695613952000 | |
use Test::More tests => 2; | |
use Mojo::Loader; | |
# output redirection copy-paste credit | |
# http://stackoverflow.com/questions/1538260/how-can-i-unit-test-perl-functions-that-print-to-the-screen | |
sub capture_stdout { | |
my $sub = shift; | |
my $stdout; | |
{ | |
local *STDOUT; | |
open STDOUT, '>', \$stdout | |
or die "Cannot open STDOUT to a scalar: $!"; | |
$sub->(@_); | |
close STDOUT | |
or die "Cannot close redirected STDOUT: $!"; | |
} | |
return $stdout; | |
} | |
# current behaviour: | |
# | |
# is( | |
# capture_stdout( | |
# sub { Mojo::Loader->load(qq{Mojo::Loader; print "Nice Feature";}); } | |
# ), | |
# "Nice Feature", | |
# "loader executes arbitrary code" | |
# ); | |
# is(capture_stdout(sub { Mojo::Loader->load(qq{print "Nice Feature";}); }), | |
# "Nice Feature", "loader executes arbitrary code no module"); | |
# not sure what the correct behaviour should be - silently avoid code execution or | |
# throw exception? | |
# | |
is( | |
capture_stdout( | |
sub { Mojo::Loader->load(qq{Mojo::Loader; print "Nice Feature";}); } | |
), | |
"", | |
"loader executes arbitrary code" | |
); | |
is(capture_stdout(sub { Mojo::Loader->load(qq{print "Nice Feature";}); }), | |
"", "loader executes arbitrary code no module"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment