Solved

CGI.pm > 2.98 sends malformed headers

Posted on 2003-11-12
13
833 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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now