Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the source of a perl taint mode error

Tags:

cgi

perl

taint

When running a perl CGI script in taint mode, I get an error of the form...

Insecure dependency in some_function while running with -T switch at (eval some_line) line some_other_line.
Compilation failed in require at my-script.cgi line 39.
BEGIN failed--compilation aborted at my-script.cgi line 39.

my-script.cgi line 39 is a use statement for a perl module which does not itself use eval or some_function, but presumably uses another library which does. The some_line and some_other_line line numbers don't seem to make sense in either my-script.cgi or the library which is 'use'd on line 39 of my-script.cgi.

Given this error, how can I track down where the taint error is occurring?

I've tried setting a new die signal handler which should print a stack trace, i.e.

$SIG{ __DIE__ } = sub { require Carp; Carp::confess(@_); };

but this seems to have no effect on the error. Perhaps this is the wrong signal to be trapping, not happening early enough, or something more complex is required.

like image 559
Matt Sheppard Avatar asked Jun 15 '11 05:06

Matt Sheppard


2 Answers

Carp::Always works fine with exceptions raised by taint checks. Example output:

$ perl -MCarp::Always -T blah.pl
Insecure dependency in sprintf while running with -T switch at blah.pl line 6
        main::foo() called at blah.pl line 8
        main::bar() called at blah.pl line 10
like image 146
daxim Avatar answered Nov 04 '22 13:11

daxim


I use Devel::SimpleTrace a lot these days for debugging and it recently helped me find a taint bug when using Archive::Zip.

However, I don't know if it would have worked in your case since it is essentially setting the same sig handler that you used.

like image 2
jmcnamara Avatar answered Nov 04 '22 11:11

jmcnamara