develooper Front page | perl.perl5.porters | Postings from November 2004

[perl #30424] BUG REPORT PERL / CGI ...: CGI / mod_perl / $query->defaults('defaults')

Thread Next
From:
Steve Peters via RT
Date:
November 23, 2004 03:42
Subject:
[perl #30424] BUG REPORT PERL / CGI ...: CGI / mod_perl / $query->defaults('defaults')
Message ID:
rt-3.0.11-30424-100855.4.12787998632943@perl.org
> [contact@uuukkk.net - Wed Jun 23 02:26:28 2004]:
> 
> Wednesday, 2004 June 23rd
> 
> Bug report:
> 
>     * Apache 2.x
>     * mod_perl 1.99x
>     * CGI
>     * $query->defaults('defaults') [ please, press the defaults button
>       to reproduce the fault !!! ]
> 
> Please run the following PERL script under mod_perl, Apache,
> and press the defaults button: this will produce the nasty error.
> 
> Uncomment "use CGI::Carp qw(fatalsToBrowser);#report erro to client"
> or check "F:\Applications\ApacheGroup\Apache2\logs\error.log" (adjust to 
> your path)
> to see the erro message:
> 
>     * [Wed Jun 23 11:02:30 2004] [error] 2924: ModPerl::Registry: Can't
>       call method "send_cgi_header" on an undefined value at (eval 9)
>       line 62.\n
> 
> This leads into cgi.pm, line 1360:
> 
>     *     if ($MOD_PERL and not $nph) {
>               $self->r->send_cgi_header($header);
>               return '';
>           }
>           return $header;
> 
> Setting nph or not doesn't help.
> 
> I think it is a bug.
> 
> One cannot run the following script under Apache's mod_perl.
> 
> Besides, the script runs fine under Apache's cgi-bin,
> 
> Please keep me posted.
> 
> Best regards, Uwe Karasek
> ------------------------------------------------------------------------
> #
> # script: saveRestorState.pl
> #
> # Save and restore the state of a form to a file
> 
> use strict;
> 
> use CGI qw(-nph);
> #use CGI::Carp qw(fatalsToBrowser);#report erro to client
> 
> use vars qw($query); # global variable: $main::query
> 
> $query = new CGI;
> 
> print $query->header(-charset=>'UTF-8');
> print
>   $query->start_html
>   (
>     -title=>'Save and restore the state of a form to a file',
>     -author=>'dobby',
>     -meta=>{'keywords'=>'cgi object save restore','copyright'=>'dobby'},
>     -encoding=>'UTF-8'
>   ),
>     $query->h1('Save and Restore Example');
> 
>     # Here's where we take action on the previous request
>     my $tst=$query->param('action');
>     $tst='' if !defined $tst;
>     if ($tst eq 'save')
>     {
>       &saveParameters($query) ;
>     }
>     if ($tst eq 'restore')
>     {
>       $query = &restoreParameters($query) ;
>     }
> 
>     # Here's where we create the form
>   print
>     $query->start_multipart_form(),
>       'Popup 1: ',
>       $query->popup_menu
>       (
>         'popup1',
>         [qw{red green purple magenta orange chartreuse brown}],
>         'magenta'
>       ),
>       'Popup 2: ',
>       $query->popup_menu
>       (
>         'popup2',
>         [qw{lion tiger bear zebra potto wildebeest frog emu gazelle}],
>         'zebra'
>       ),
>       $query->p()
>       ;
>       my $default_name = $query->remote_addr() . '.sav';
>     print
>       'Save / restore state from file: ',
>       $query->textfield
>       (
>         'savefile',
>         $default_name
>       ),
>       $query->p(),
>       $query->submit('action','save'),
>       ' ',
>       $query->submit('action','restore'),
>       ' ',
>       $query->defaults('defaults'), #Create a "defaults" button.
>     $query->endform();
> 
> # Here we print out a bit at the end
> print
>   $query->end_html();
> 
> sub saveParameters
> {
>   local($query) = @_;
> 
>   my($filename) = &cleanName($query->param('savefile'));
>   if (open(FILE,">$filename"))
>   {
>     $query->save('FILE');
>     close FILE;
>     print
>       $query->strong("State has been saved to file $filename\n"),
>       $query->p(),
> "If you remember this name you can restore the state later.\n";
>   }
>   else
>   {
>     print
>       $query->strong('Error: '),
>       "couldn't write to file $filename: $!",
>       $query->p()
>       ;
>   }
> }
> 
> sub restoreParameters
> {
>   local($query) = @_;
>   my($filename) = &cleanName($query->param('savefile'));
>   if (open(FILE,$filename))
>   {
>     # Throw out the old query, replace it with a new one
>     $query = new CGI('FILE');
>     close FILE;
>     print
>       $query->strong
>       (
> "State has been restored from file $filename\n"
>       );
>   }
>   else
>   {
>     print
>       $query->strong('Error: '),
>       "couldn't restore file $filename: $!\n"
>       ;
>   }
>   return $query;
> }
> 
> 
> # Very important subroutine -- get rid of all the naughty
> # metacharacters from the file name. If there are, we
> # complain bitterly and die.
> sub cleanName
> {
>   my($name) = @_;
>   unless ($name=~/^[\w\._\-]+$/)
>   {
>     print
>       $query->strong("\"$name\" has naughty characters."),
>       $query->br(),
>       $query->strong('Only alphanumerics are allowed.'),
>       $query->br(),
>       $query->strong("You can't use absolute paths either.")
>       ;
>     die "Attempt to use naughty characters";
>   }
>   return "D:/Applications/cygwin/home/Administrator/perl/$name";
> }
> ------------------------------------------------------------------------
> 

I received no errors when running this script from a command line.  You
should reopen this ticket at rt.cpan.org for the current mod_perl
distribution if you are still having this problem.


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About