Tuesday, April 15, 2008

how to untaint perl variables

variables become tainted when contain data obtained through glob(), opendir(), readdir(), etc...
to untaint path use this subroutine:

sub untaint_path
{
my $f = shift;
my $ff;
if ( $f =~ /^([\w\/\.]+)$/ ) {
$ff = $1;
}
return $ff;
}

1 Comments:

Blogger __x__ said...

this also works:

sub untaint_path
{
my $f = shift;
my $ff;
if ($f =~ /^(.*)$/) {
$ff = $1;
}
return $ff;
}

8:15 AM  

Post a Comment

<< Home