You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Arthur Bergman <ar...@contiller.se> on 2002/05/14 11:51:57 UTC

Problem with tied STDIN, CGI.pm mod_perl 1.26 and perl 5.6.1

Hi,

After tons of debugging a case when I lost CGI POST variables I 
discovered the following.

In perl 5.6.1, certain operations can cause references to filehandles to 
loose TIE magic even when the filehandle is tied.

Witness.

use strict;
use IO::Scalar;
sub IO::Scalar::FILENO {};
my $scalar = "";
tie *STDIN, 'IO::Scalar', \$scalar;
fileno(STDIN);
my $fh = \*STDIN;
print $fh "HI";
print "---$scalar---\n";

Removing the fileno(STDIN), makes the above example work. This is fixed 
in perl 5.8 to be, I don't know how far back it has effect I only tried 
it under 5.6.1.

The result is that if a module does fileno(STDIN), or any of the other 
potential ops (Anyone doing sv_setsv on a glob), any references to STDIN 
will not be tied, however since CGI.pm reads STDIN for post data from a 
reference to STDIN, and mod_perl makes it tied, suddenly post data will 
not appear.
Worst case it will hang since it does a read( from /dev/null which is 
what plain STDIN is under apache on linux).

The following patch corrects the problem without having any bad side 
effects as far as I know.


--- CGI.pm~     Wed Apr 10 21:36:01 2002
+++ CGI.pm      Tue May 14 11:34:22 2002
@@ -450,7 +450,7 @@
        }

        if ($meth eq 'POST') {
-         
$self->read_from_client(\*STDIN,\$query_string,$content_length,0)
+         
$self->read_from_client('STDIN',\$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


Arthur


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


Problem with tied STDIN, CGI.pm mod_perl 1.26 and perl 5.6.1

Posted by Lincoln Stein <ls...@cshl.org>.
No kidding!  What strange behavior.  This must be a rare circumstance,
because I've been running mod_perl and 5.6.1 for some time now.
Perhaps it is only particular versions of mod_perl?

I'll add the patch you suggest, even though passing a bareword FH to a
sub is usually considered a bad thing to do.

Lincoln

Arthur Bergman writes:
 > Hi,
 > 
 > After tons of debugging a case when I lost CGI POST variables I 
 > discovered the following.
 > 
 > In perl 5.6.1, certain operations can cause references to filehandles to 
 > loose TIE magic even when the filehandle is tied.
 > 
 > Witness.
 > 
 > use strict;
 > use IO::Scalar;
 > sub IO::Scalar::FILENO {};
 > my $scalar = "";
 > tie *STDIN, 'IO::Scalar', \$scalar;
 > fileno(STDIN);
 > my $fh = \*STDIN;
 > print $fh "HI";
 > print "---$scalar---\n";
 > 
 > Removing the fileno(STDIN), makes the above example work. This is fixed 
 > in perl 5.8 to be, I don't know how far back it has effect I only tried 
 > it under 5.6.1.
 > 
 > The result is that if a module does fileno(STDIN), or any of the other 
 > potential ops (Anyone doing sv_setsv on a glob), any references to STDIN 
 > will not be tied, however since CGI.pm reads STDIN for post data from a 
 > reference to STDIN, and mod_perl makes it tied, suddenly post data will 
 > not appear.
 > Worst case it will hang since it does a read( from /dev/null which is 
 > what plain STDIN is under apache on linux).
 > 
 > The following patch corrects the problem without having any bad side 
 > effects as far as I know.
 > 
 > 
 > --- CGI.pm~     Wed Apr 10 21:36:01 2002
 > +++ CGI.pm      Tue May 14 11:34:22 2002
 > @@ -450,7 +450,7 @@
 >         }
 > 
 >         if ($meth eq 'POST') {
 > -         
 > $self->read_from_client(\*STDIN,\$query_string,$content_length,0)
 > +         
 > $self->read_from_client('STDIN',\$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
 > 
 > 
 > Arthur
 > 

-- 
========================================================================
Lincoln D. Stein                           Cold Spring Harbor Laboratory
lstein@cshl.org			                  Cold Spring Harbor, NY
Positions available at my lab: see http://stein.cshl.org/#hire
========================================================================

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


Re: Problem with tied STDIN, CGI.pm mod_perl 1.26 and perl 5.6.1

Posted by Doug MacEachern <do...@covalent.net>.
On Tue, 14 May 2002, Arthur Bergman wrote:
 
> When is 1.27 due for release?

there's at least 1 known problem related to bleedperl (just posted to 
p5p).  the 1.27 release will probably be just before or on the same day
5.8.0 is released to make sure it'll be happy with 5.8.0



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


Re: Problem with tied STDIN, CGI.pm mod_perl 1.26 and perl 5.6.1

Posted by Arthur Bergman <ar...@contiller.se>.
On lördag, juni 15, 2002, at 06:34 , Doug MacEachern wrote:

>
>>> the problem was fixed in bleedperl #11536/11553
>>> modperl-2.0 has a workaround for the problem when 5.6.1 is being used
>>> (see
>>> code within #ifdef MP_REFGEN_FIXUP in mod_perl.c).  might consider
>>> adding
>>> it for for 1.27
>
> fyi - i did not put this workaround into 1.27 and no plans for 1.28.
> i'd say: use 5.8.0 and/or start using 1.99_xx on win32
>
> it isn't worth spending time attemping to "improve" modperl-1.xx on 
> win32
>

That is fine with me, we are in the progress of going there anyhow.

Arthur


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


Re: Problem with tied STDIN, CGI.pm mod_perl 1.26 and perl 5.6.1

Posted by Doug MacEachern <do...@covalent.net>.
> > the problem was fixed in bleedperl #11536/11553
> > modperl-2.0 has a workaround for the problem when 5.6.1 is being used 
> > (see
> > code within #ifdef MP_REFGEN_FIXUP in mod_perl.c).  might consider 
> > adding
> > it for for 1.27

fyi - i did not put this workaround into 1.27 and no plans for 1.28.
i'd say: use 5.8.0 and/or start using 1.99_xx on win32

it isn't worth spending time attemping to "improve" modperl-1.xx on win32



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


Re: Problem with tied STDIN, CGI.pm mod_perl 1.26 and perl 5.6.1

Posted by Arthur Bergman <ar...@contiller.se>.
On tisdag, maj 14, 2002, at 04:59 , Doug MacEachern wrote:

> On Tue, 14 May 2002, Arthur Bergman wrote:
>
>> Hi,
>>
>> After tons of debugging a case when I lost CGI POST variables I
>> discovered the following.
>>
>> In perl 5.6.1, certain operations can cause references to filehandles 
>> to
>> loose TIE magic even when the filehandle is tied.
>
> you left out an important piece of info: this only happens with ithreads
> enabled.
>
> the problem was fixed in bleedperl #11536/11553
> modperl-2.0 has a workaround for the problem when 5.6.1 is being used 
> (see
> code within #ifdef MP_REFGEN_FIXUP in mod_perl.c).  might consider 
> adding
> it for for 1.27
>
>
>

Ah, well, I run mod_perl under windows with AS perl, so ithreads was 
pretty much enabled :), and I always run my perls with ithreads anyway 
(what else could I do!).

When is 1.27 due for release?

Arthur


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


Re: Problem with tied STDIN, CGI.pm mod_perl 1.26 and perl 5.6.1

Posted by Doug MacEachern <do...@covalent.net>.
On Tue, 14 May 2002, Arthur Bergman wrote:

> Hi,
> 
> After tons of debugging a case when I lost CGI POST variables I 
> discovered the following.
>
> In perl 5.6.1, certain operations can cause references to filehandles to 
> loose TIE magic even when the filehandle is tied.

you left out an important piece of info: this only happens with ithreads 
enabled.

the problem was fixed in bleedperl #11536/11553
modperl-2.0 has a workaround for the problem when 5.6.1 is being used (see 
code within #ifdef MP_REFGEN_FIXUP in mod_perl.c).  might consider adding 
it for for 1.27




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


Re: Problem with tied STDIN, CGI.pm mod_perl 1.26 and perl 5.6.1

Posted by Matt Sergeant <ma...@sergeant.org>.
On Tue, 14 May 2002, Arthur Bergman wrote:

> The following patch corrects the problem without having any bad side
> effects as far as I know.

IIRC there are earlier perl 5's where file handles as a string rather than
a globref don't work. But I'm talking like 5.001 or something, so I
wouldn't worry about it too much.

> --- CGI.pm~     Wed Apr 10 21:36:01 2002
> +++ CGI.pm      Tue May 14 11:34:22 2002
> @@ -450,7 +450,7 @@
>         }
>
>         if ($meth eq 'POST') {
> -
> $self->read_from_client(\*STDIN,\$query_string,$content_length,0)
> +
> $self->read_from_client('STDIN',\$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

-- 
<!-- Matt -->
<:->Get a smart net</:->


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