Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This code works just fine on my platform from both the command line and my browser. Those of you who have read the CGI Programming book should recognize the code.

Anyway, here's the code:

#!/usr/bin/perl -wT
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI;
my $q = new CGI;
#line 5#
print $q->header( "text/plain" );
print "These are the HTTP Environment variables that I got.\n\n";

foreach ($q->http ) {
 print  "$_\n";
print " ". $q->http( $_ ), "\n";
}

However, when I uploaded this to another site, it wouldn't work and here's what I got in the server log:

Too late for "-T" option at expermint.cgi line 1. Could not fire up expermint.cgi

I have several other scripts at that site that generate the same errors when I leave the -T mode on. I uploaded this script to the other site because I was certain it was not my code that was generating this error.

The tech people at that site said that they were unable to get the code to work even with the -T on off thus implying there is something wrong with the above code itself.

So I uploaded it to another site and I was able to get it work.

So then I decide to leave off the -T and got some unexpected output along with the expected output:

<Iframe ><html_code><annoying_ad.png ></html_code ></iframe>

The rest of the output was as expected.

As soon as I saw the unexpected html, I realized why I had been getting the errors with the -T on.

It so happens that my account is free and in order for me to keep the account, I have to accept ads on both my webpages and my cgi scripts. I'm certain that the ads are the reason behind my errors. There is no way my scripts could untaint that!

Now, I must admit here that I'm no computer or Perl guru and it is possible that the code itself is faulty and I want to know if there are other reasons why I keep getting this error?

However, there is no reason why all of my scripts should generate the same error - especially when one of my scripts doesn't depend on input from my web browser.

Any input would be much appreciated. Sorry for the long post.

Replies are listed 'Best First'.
Re: Too late for "-T" option
by Errto (Vicar) on Oct 10, 2004 at 00:22 UTC

    I highly doubt that the advertising is what is causing your error. What that error message means is that Perl cannot run in your code in taint mode at all. The difference is presumably this: on your own site, the Perl CGI's are running as straight CGIs; that is, the OS is actually executing the Perl scripts directly. However, on the other host provider, your CGI's are being invoked in some other way, and Perl cannot retroactively apply tainting.

    The solution is to discuss with the hosting provider what mechanism they use to execute your CGI scripts, and ask them if they can just run it as straight CGI.

    The full explanation is here (from perldiag):

     Too late for "-T" option
               (X) The #! line (or local equivalent) in a Perl script contains the
               -T option, but Perl was not invoked with -T in its command line.
               This is an error because, by the time Perl discovers a -T in a
               script, it’s too late to properly taint everything from the envi-
               ronment.  So Perl gives up.
     
               If the Perl script is being executed as a command using the #!
               mechanism (or its local equivalent), this error can usually be
               fixed by editing the #! line so that the -T option is a part of
               Perl’s first argument: e.g. change "perl -n -T" to "perl -T -n".
     
               If the Perl script is being executed as "perl scriptname", then the
               -T option must appear on the command line: "perl -T scriptname".
     
    
Re: Too late for "-T" option
by tachyon (Chancellor) on Oct 10, 2004 at 02:59 UTC

      Thanks all for your input and I must say your explainations make better sense than my own.

      Interesting as it's possible that the host is on a Windows platorm. I certainly will ask the tech people about the platfrom that it's on. I'll also ask how they implement the scripts,

      Speaking for me, I'm an OS X user and not too familar with the Windows platform.

      Guess I'll I have to learn Windows as well.

        Just checked out their page on techology. My host uses both FreeBSD and LInux so I think we can rule out the Windows platfrom as being the cause of the problem.

        I believe the OS X is based on FreeBSD. I'm using the Panther verision.

        Guess I"ll have to ask the tech people if i can run CGI straight from the platfrom or if the script is being invoked some other way.

        I'll ask about that module thing too.

Re: Too late for "-T" option
by hsinclai (Deacon) on Oct 10, 2004 at 00:49 UTC
    It's possible that your provider runs mod_perl in Apache::PerlRun mode, and the PerlTaintCheck directive is absent from the config file or set to Off.