perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitry Karasik <dmi...@karasik.eu.org>
Subject [mp2] mod_perl closes apache's stdin and/or stdout
Date Mon, 01 Oct 2007 14:49:57 GMT
Hello,

As a follow-up to my previous bug report to users@,
( http://www.gossamer-threads.com/lists/modperl/modperl/94912 )
I'd like to re-post the same issue to dev@, because I'm unsure 
what is the status of this bugreport, and basically if it
was recognized as one.

Just for the sake if the test wasn't reproduced correctly, I'll rerun:

1) test setup:

	add to httpd.conf:

<LocationMatch "^/cgi-bin/m.cgi$">
               SetHandler perl-script
               PerlResponseHandler ModPerl::Registry
               PerlOptions +ParseHeaders
</LocationMatch>

<LocationMatch "^/cgi-bin/a.cgi$">
               SetHandler cgi-script
</LocationMatch>


	both cgis are identical, and are:

#!/usr/bin/perl -w
print "Content-type: text/html\n\n", $ENV{MOD_PERL}||'', "\n", <STDIN>, "\n";

	test.pl:

open F, "|nc localhost 80"; # this requires netcat because I'm lazy
print F <<R;
POST /cgi-bin/m.cgi HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: 13
Keep-Alive: 300

submit=Submit

POST /cgi-bin/a.cgi HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: 13
Keep-Alive: 0
Connection: close

submit=Submit
R

2) 

- now, stop apache, run it from console as 'httpd -X' ( or apache2 -X on some linux distros)
- run 'perl test.pl'

The bug manifests itself in that the following apache response is printed out (some lines
are skipped):

HTTP/1.1 200 OK
1d
mod_perl/2.0.3
submit=Submit
0

HTTP/1.1 200 OK
Connection: close
Content-Type: text/html
2
0

and the second request doesn't contain 'submit=Submit' line.

This can be fixed by applying the following patch:

--- modperl_io.c.orig 2007-09-25 15:36:02.000000000 +0200
+++ modperl_io.c 2007-09-25 15:35:51.000000000 +0200
@@ -129,6 +129,15 @@
Perl_croak(aTHX_ "Failed to dup STDIN: %" SVf, get_sv("!", TRUE));
}

+ /* In mixed environment of mod_perl and cgi scripts, cgi scripts may read content of
+ * POST requests off STDIN. do_close() calls actual close(0), freeing the descriptor 0
+ * for reuse, and creating havoc for anyone reading from file descriptor 0.
+ * This hack changes the IO type to IoTYPE_STD, because do_close() does not call
+ * underlying close() on IO handles of these types, but does free the associated
+ * resources. */
+ if ( IoIFP(io) && PerlIO_fileno(IoIFP(io)) == 0)
+ IoTYPE(io) = IoTYPE_STD;
+
/* similar to PerlIO::scalar, the PerlIO::Apache layer doesn't
* have file descriptors, so STDIN must be closed before it can
* be reopened */

So, I'm not sure what other information I can provide, please tell me if there's anything
more, because I'd love to see that bug fixed.

-- 
Sincerely,
	Dmitry Karasik


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Mime
View raw message