in reply to Detect SQL injection
$type =~ s/\s+/ /g; # Liberal for inputs, strict for outputs. $type =~ s/^\s//; $type =~ s/\s\z//; $type = uc($type); $type =~ / ^ (?: VARCHAR (?: \s* \( \s* [0-9]+ \s* \) )? | CHAR (?: \s* \( \s* [0-9]+ \s* \) )? | ... ) \z /x or die;
You could also accept two fields, one of them a drop down. The user wouldn't have to know SQL.
if ($type eq 'VARCHAR') { if ($arg eq '') { $sql = $type; } elsif ($arg =~ /^[0-9]+\z/) { $sql = "$type($arg)"; } else { die } } elsif ($type eq 'CHAR') { if ($arg eq '') { $sql = $type; } elsif ($arg =~ /^[0-9]+\z/) { $sql = "$type($arg)"; } else { die } } ... else { die }
|
|---|