Solved

CGI.pm > 2.98 sends malformed headers

Posted on 2003-11-12
13
836 Views
Last Modified: 2012-06-22
Setup:
FreeBSD 5.1
Apache 1.3.29 + PHP 4.3.4 + mod_perl 1.29
perl 5.8.2 from ports
scripts in question running under mod_cgi, not mod_perl

Script (for simplicities sake):
#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
die "i'm dead!";

When I run a script (like the one above, or anything using CGI::Carp) under mod_cgi using the CGI.pm 2.99 or 3.0 package, I get the following an internal server error and a the following line appears in the error log:

[Tue Nov 11 20:49:30 2003] [error] [client 69.3.236.134] malformed header from script. Bad header=<pre>my error: /path/to/script/test.cgi

If I downgrade to CGI.pm 2.98 or below, I do not get these errors and everything works flawlessly.  I've posted to a couple of perl lists and nobody can figure it out.  I've tried stripping down to a basic httpd.conf, removing all the mod_perl and php directives, but I still get the same error.  Every other function of CGI.pm 3.0 works, it's just the CGI::Carp stuff that errors.

Any ideas?  If you have any questions about my setup and whatnot just ask. Thanks!

-j
0
Comment
Question by:dbunder
  • 5
  • 3
  • 2
  • +2
13 Comments
 
LVL 16

Expert Comment

by:_nn_
ID: 9730536
It looks like a known issue : http://www.mail-archive.com/beginners-cgi@perl.org/msg08913.html
I suggest reading the whole thread. I found http://www.mail-archive.com/beginners-cgi@perl.org/msg08928.html specially interesting, but all messages are apparently valuable.

As for the origin of the problem, I suspect that this change is responsible :

<quote>
CHANGE LOG
(...)
1.26 Replaced CORE::GLOBAL::die with the evil $SIG{__DIE__} because the former isn't working in some people's hands. There is no such thing as reliable exception handling in Perl.
</quote>
0
 
LVL 1

Author Comment

by:dbunder
ID: 9733831
I noticed this in the changelog and changed it back to CORE::GLOBAL::die and still got the same error.
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9734135
:/ ... well then, it's probably more subtle and beyond my current investigation abilities. I'll add that I globally agree with what was said in the mentioned thread, e.g. change the way fatal errors are dealt with (did you try the set_message "hook" ?), before wishing you good luck. Hopefully, a Perl expert (I'm not) will be able to help you.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Expert Comment

by:LTGrey
ID: 9734702
What happens when you run this at the console?
-LTG
0
 
LVL 1

Author Comment

by:dbunder
ID: 9734976
CGI.pm 2.98:
Content-type: text/html

<h1>Software error:</h1>
<pre>i'm dead! at t.pl line 3.</pre>
<p>
For help, please send mail to this site's webmaster, giving this error message
and the time and date of the error.

</p>
[Wed Nov 12 13:44:09 2003] t.pl: i'm dead! at t.pl line 3.

CGI.pm 2.99 and 3.0:
<h1>Software error:</h1>
<pre>i'm dead! at t.pl line 3.</pre>
<p>
For help, please send mail to this site's webmaster, giving this error message
and the time and date of the error.

</p>
[Wed Nov 12 13:42:27 2003] t.pl: i'm dead! at t.pl line 3.
0
 
LVL 1

Author Comment

by:dbunder
ID: 9735606
a little bit more info.

i diffed 2.98 and 3.00 and noticed that 3.00 has some new checks for mod_perl.  when these checks test positive for mod_perl, CGI::Carp doesn't send a header, since mod_perl should do that for you automatically.

the way it checks to see if it is running under mod_perl is it checks if $ENV{MOD_PERL} exists.  i ran a script under the webserver to check for $ENV{MOD_PERL} and it came up negative.  so it wasn't that.  but just to be safe, i edited Carp.pm so it always tests negative for mod_perl no matter what the conditions.  still got the same error.  

even more baffled now.
0
 

Expert Comment

by:LTGrey
ID: 9782406
Ignore this V.V. points, but if you hand roll your headers in 2.99 and 3.0, you should remove the malformed headers problem

The notion of a CGI module is that you shouldn't have to do this, but in 2.99 and 3.0, it looks like they've got a lot stricter, and you haven't made a call to [b]start_html()[/b] which would have generated the header
LTG
0
 
LVL 1

Author Comment

by:dbunder
ID: 9782521
CGI::Carp's die() subroutine (when fatalsToBrowser is imported) explicitly sends a well-formed header.  But for some reason the newer versions of CGI.pm don't send it.  Still confused.  But 2.98 works fine.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9782592
I agree that the question has not been answered, but I'd like to see this question PAQed.

The behavior of 2.99 and 3.0 revs of CGI looks wrong, since the whole point of fatalsToBrowser is to arrange for a sensible HTML-format document to be sent to the browser in the event that an error occurs. It has to do this even if no code in the script manages to get executed. Having this record of the problem may speed resolution of similar problems in the future.
0
 
LVL 1

Author Comment

by:dbunder
ID: 9783569
Good idea, jmcg!  I agree.
0
 

Expert Comment

by:LTGrey
ID: 9783891
Concurred
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 9803230
PAQed, with points refunded (175)

Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question