My dear fellow programmers

I am in need of thy help!

I have just activated the -T switch in all my scripts and everything went smoothly untill I run into the "unlink" command. He seems not to accept my untainting regexp, complaining "Insecure dependency in unlink while running with -T switch...". Here goes my code:

my $subcookie = untaint ( substr($cookie,0,6) ); # this is a substring + of the SID, that I use as a name for a dinamic directory for the use +r. Also, check my untaint() function below opendir (DIR, "../users/$subcookie/"); # I was using glob, but couldn´ +t make -T accept it, so I changed to readdir my @files = readdir DIR; foreach my $file (@files) { my $checked_file; if ( $file =~ /(\w+)\.(\w{3,4})/ ) { $checked_file = "$1.$2"; } # a +voiding the first "." and ".." thar readdir returns if ( defined $checked_file ) { unlink "../users/$subcookie/$checked +_file"; } } close DIR; ... # and the code goes on
Here´s the untaint() function, wich is 'require'd from another .cgi:
sub untaint { my $string = shift; my $clean_string; if ( $string =~ /([\w\-\_]+)/ ) { $clean_string = $1; } else { die "ilegal character: $!"; } return $clean_string; }
Anyone knows what might be? Is there a less demanding function I can use to wipe out all the files in this directory?

Thanks a lot, my friends!

André


In reply to Unlink under taint mode by Andre_br

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.