#!/usr/bin/perl -T use warnings; use strict; use Scalar::Util qw(tainted); use CGI qw(:standard); BEGIN { if ($ENV{REQUEST_METHOD}) { eval 'use CGI::Carp qw(fatalsToBrowser)'; } } use constant EOL => $ENV{REQUEST_METHOD} ? "
\n" : "\n"; if ($ENV{REQUEST_METHOD}) { start_html(); } my $file = param('file') or die "No filename given"; # The next 3 lines will untaint the variable. $file =~ /^(\w+)$/ or die "illegal filename\n"; $file = $1; printf "\$file is%s tainted.".EOL,tainted($file)?"":"n't"; open(F,">> /tmp/$file") or die "Couldn't open file"; print F "Wrote.\n"; close(F); print "OK".EOL; if ($ENV{REQUEST_METHOD}) { end_html(); }