I've distilled all this advice this as best I can.
============
something.lib
============
sub safer {
my $hash = shift;
my %safer;
while (my ($k, $v) = each %$hash) {
s/\\//g for $k, $v;
s/0x00//g for $k, $v;
s/0x08//g for $k, $v;
s/0x09//g for $k, $v;
s/0x0a/\n/g for $k, $v;
s/0x0d/\r/g for $k, $v;
s/"/\\"/g for $k, $v;
s/%/\\%/g for $k, $v;
s/'/\\'/g for $k, $v;
s/_/\_/g for $k, $v;
$safer{$k} = $v;
}
return %safer;
}
================
something.cgi...
================
use warnings;
use strict;
use CGI;
use CGI::Carp;
print "Content-type: text/html\n\n";
# marker
my $cgi = CGI->new();
$cgi->param;
my %params;
for my $name ($cgi->param) {
my @values = $cgi->param($name);
$params{$name} = @values > 1 ? \@values : $values[0];
}
%params=safer(\%params);
# marker
for my $param (keys %params) {
print "$param: $params{$param}<br>"
}
The stuff between the two markers will replace the existing
sub main
{
my $cgi = CGI->new();
my %params = $cgi->Vars();
... in the existing scripts. This is running under mod-perl (w/ regcooker).
Are there any "gotchas" I should be aware of here?
Thanks to all you monks for all your help!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.