I thought this taint check worked on usernames composed of letters or numbers from 1-16 characters, but apartently it does not. Anyone have any thoughts as to why?
lib.pl ------------- package lib; use vars '%common'; %common = ( 'username' => " " ); sub untaint_username { my $tainted = shift; # patern match letters and numbers for 1-16 characters (inclusive) $tainted =~ s/\W//g; # remove all non word characters if ($tainted =~ /\A([a-zA-Z0-9]{1-16})\z/i) { return $1; } # behold a username else {print "failure\n";} } 1;
----------------- prog.pl ----------------- #!/usr/bin/perl -wT use strict; require './lib.pl'; $lib::common{username}="unixhelp"; $lib::common{username}=lib::untaint_username($lib::common{username});
I dont think that anything weird is going on, so I guess the expression doesnt match what I think it does.

jcpunk
all code is tested, and doesn't work so there :p (varient on common PM sig for my own ammusment)

In reply to taint check that I thought worked by jcpunk

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.