You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Ronald Schmidt <rs...@net2phone.com> on 2000/06/14 14:49:57 UTC

uninitialized value at ... CGI/Cookie.pm line 70.

The full warning message on our system (Solaris, Apache 1.3.3, mod_perl
1.21?, perl 5.005_02) is:

[Tue Jun 13 17:37:25 2000] null: Use of uninitialized value at
/usr/local/lib/perl5/5.00502/CGI/Cookie.pm line 70.

We are porting perl/cgi scripts to run under Apache;:Registry and in the
process of porting I am getting the warning above from one of the scripts.
In investigating the problem I went to
http://perl.apache.org/guide/porting.html to look for examples of cookie use
with mod_perl.  I found that with slight modification to one of the samples
I could re-produce the problem.  The modification involved moving the
initialization of a CGI object reference out of a subroutine.  Initializing
our $q = new CGI; in a subroutine would mean re-arranging a fair amount of
code in our scripts.  Has anyone hit this before? Does anyone have a
suggestion for getting around the problem?  The code that reproduces the
problem follows.

Ronald Schmidt

PS I am a mod_perl newbie.  Go easy.  Newbies are people too.

  use strict;
  use CGI;
  use CGI::Cookie;
  use vars qw($q $switch $status $sessionID);
  use diagnostics;
  
    $q = new CGI; # this seems to trigger the problem

  init();
  print_header();
  print_status();
  
  ### <-- subroutines --> ###
  
  # the init code
  ###########
  sub init{
#    $q = new CGI; # move this up to exhibit bug
    
    $switch = $q->param("switch") ? 1 : 0;
    
      # try to retrieve the session ID
              # fetch existing cookies
    my %cookies = CGI::Cookie->fetch;
    $sessionID = exists $cookies{'sessionID'} 
       ? $cookies{'sessionID'}->value : '';
    
      # 0 = not running, 1 = running
    $status = $sessionID ? 1 : 0;
    
      # switch status if asked to
    $status = ($status+1) % 2 if $switch;
    
    if ($status){
        # preserve sessionID if exists or create a new one
      $sessionID ||= generate_sessionID() if $status;
    } else {
        # delete the sessionID
      $sessionID = '';
    }
    
  } # end of sub init
  
  #################
  sub print_header{
      # prepare a cooke
    my $c = CGI::Cookie->new
      (-name    => 'sessionID',
       -value   => $sessionID,
       -expires => '+1h');
    
    print $q->header
      (-type   => 'text/html',
       -cookie => $c);
  
  } # end of sub print_header
  
  

Re: uninitialized value at ... CGI/Cookie.pm line 70.

Posted by Drew Taylor <dt...@vialogix.com>.
Ronald Schmidt wrote:
> 
> The full warning message on our system (Solaris, Apache 1.3.3, mod_perl
> 1.21?, perl 5.005_02) is:
> 
> [Tue Jun 13 17:37:25 2000] null: Use of uninitialized value at
> /usr/local/lib/perl5/5.00502/CGI/Cookie.pm line 70.
Which line is #70 in the script you posted? It's kind of hard to tell
since it looks like you snipped some lines.

-- 
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/

Re: uninitialized value at ... CGI/Cookie.pm line 70.

Posted by darren chamberlain <da...@boston.com>.
Ronald Schmidt (rschmidt@net2phone.com) said something to this effect:
> The full warning message on our system (Solaris, Apache 1.3.3, mod_perl
> 1.21?, perl 5.005_02) is:
> 
> [Tue Jun 13 17:37:25 2000] null: Use of uninitialized value at
> /usr/local/lib/perl5/5.00502/CGI/Cookie.pm line 70.
> 
> We are porting perl/cgi scripts to run under Apache;:Registry and in the
> process of porting I am getting the warning above from one of the scripts.
> In investigating the problem I went to
> http://perl.apache.org/guide/porting.html to look for examples of cookie use
> with mod_perl.  I found that with slight modification to one of the samples
> I could re-produce the problem.  The modification involved moving the
> initialization of a CGI object reference out of a subroutine.  Initializing
> our $q = new CGI; in a subroutine would mean re-arranging a fair amount of
> code in our scripts.  Has anyone hit this before? Does anyone have a
> suggestion for getting around the problem?  The code that reproduces the
> problem follows.
> 
> Ronald Schmidt

I always find it easier to parse the cookies myself, rather than rely on
{Apache,CGI}::Cookie. I use something like:

    my %cookies = map { $1 => $2 if (/([^=]+)=(.*)/) }
                  grep !/^$/, split /;\s*/,$r->header_in('cookie');

and then %cookies has the names as keys, and the values as values. Creating
cookies is a matter; I usually join vars on '; '.

I would try using this method to fetch the cookies, and then dump them
to STDERR and see what you have. I have found that browsers can mangle
cookies, and then of course no cookie parsing module will help.

darren

-- 
Wise people think all they say; fools say all they think.

Re: uninitialized value at ... CGI/Cookie.pm line 70.

Posted by Drew Taylor <dt...@vialogix.com>.
Adriano Nagelschmidt Rodrigues wrote:
> 
> Ronald Schmidt writes:
> > The full warning message on our system (Solaris, Apache 1.3.3, mod_perl
> > 1.21?, perl 5.005_02) is:
> >
> > [Tue Jun 13 17:37:25 2000] null: Use of uninitialized value at
> > /usr/local/lib/perl5/5.00502/CGI/Cookie.pm line 70.
> 
> Hi,
> 
> I see this too. In my case I think Netscape's the culprit. It is sending
> Apache the following (malformed?) cookie:
> 
> Cookie: SITESERVER=ID=72da5a605e8cda8a2592065373b1f4c2; SafiraSID=1%3Ac8887045f923541e; 700:c318af8d6350ce2c
Well, that is certainly a malformed cookie! It should be "name=value",
so this cookie will obviously fail normal cookie parsing. The question
is: is Netscape or the original server the culprit? Who first mangled
the cookie? :-)

-- 
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/

Re: uninitialized value at ... CGI/Cookie.pm line 70.

Posted by Adriano Nagelschmidt Rodrigues <an...@ime.usp.br>.
Ronald Schmidt writes:
> The full warning message on our system (Solaris, Apache 1.3.3, mod_perl
> 1.21?, perl 5.005_02) is:
> 
> [Tue Jun 13 17:37:25 2000] null: Use of uninitialized value at
> /usr/local/lib/perl5/5.00502/CGI/Cookie.pm line 70.

Hi,

I see this too. In my case I think Netscape's the culprit. It is sending
Apache the following (malformed?) cookie:

Cookie: SITESERVER=ID=72da5a605e8cda8a2592065373b1f4c2; SafiraSID=1%3Ac8887045f923541e; 700:c318af8d6350ce2c

CGI then splits pairs on ';' and keys and values on '='. You end up with a key
(700:c318af8d6350ce2c) without value. Then, line 70,

my(@values) = map CGI::unescape($_),split('&',$value);

triggers the warning.

Regards,

--
Adriano