I have a form of application server that runs as a CGI in a modperl 2 system, where the client submits a request in XML format, using a POST request.
Last night an error was reported - looking in the log I saw that the data from the POST had been truncated. After a bit of searching, including using tcpdump to verify that the data was really being sent correctly, I found a post on the modperl mailing list which pointed in the right direction.
It appears that in some circumstances apache 2/modperl 2 don't read the full POST in a single call.
CGI.pm has the following call to read the POST:
The problem here is that $self->r->read() doesn't necessary read $len bytes, and CGI.pm doesn't check this.sub read_from_client { my($self, $buff, $len, $offset) = @_; local $^W=0; # prevent a warning return $MOD_PERL ? $self->r->read($$buff, $len, $offset) : read(\*STDIN, $$buff, $len, $offset); }
My fix, based on a fix posted by Stas Bekman in the modperl list, is to simply call read_from_client() in a loop. The patch to CGI.pm (version 3.01) looks like this:
Michael*** CGI.pm~ 2003-12-12 15:09:45.000000000 -0800 --- CGI.pm 2003-12-12 15:12:29.000000000 -0800 *************** *** 551,558 **** } if ($meth eq 'POST') { ! $self->read_from_client(\$query_string,$content_length,0) ! if $content_length > 0; # Some people want to have their cake and eat it too! # Uncomment this line to have the contents of the query string # APPENDED to the POST data. --- 551,565 ---- } if ($meth eq 'POST') { ! if($content_length > 0) { ! my $len = $content_length; ! while ($len > 0) { ! my $data = ''; ! my $read = $self->read_from_client(\$data,$content_length,0); ! $len -= $read; ! $query_string .= $data if $read > 0; ! } ! } # Some people want to have their cake and eat it too! # Uncomment this line to have the contents of the query string # APPENDED to the POST data.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI.pm bug in Apache 2/mod-perl 2 setup
by tachyon (Chancellor) on Dec 13, 2003 at 02:48 UTC | |
by mpeppler (Vicar) on Dec 13, 2003 at 17:52 UTC | |
|
Re: CGI.pm bug in Apache 2/mod-perl 2 setup
by tilly (Archbishop) on Dec 13, 2003 at 22:42 UTC | |
by mpeppler (Vicar) on Dec 14, 2003 at 16:52 UTC | |
by shenme (Priest) on Dec 14, 2003 at 00:12 UTC |