The documentation for glob() has:

"If non-empty braces are the only wildcard characters used in the glob, no filenames are matched, ..."

In "perlsec: Taint mode", the long list of examples has (near the end):

@files = <*.c>; # insecure (uses readdir() or similar) @files = glob('*.c'); # insecure (uses readdir() or similar) # In either case, the results of glob are tainted, since the list of # filenames comes from outside of the program.

I'm an extremely infrequent user of glob(); however, I thought it could be useful in a test I was writing yesterday. The code looked something like this:

#!perl -T use 5.032; use warnings; ... my @prefixes = qw{...}; my @suffixes = glob '{,x}{,y}{,z}'; ... for my $prefix (@prefixes) { for my $suffix (@suffixes) { my $name = join '_', $prefix, split //, $suffix; # run is(...) test with $name here } }

I got a "tainted" message. This code fixed it:

my $tainted_name = join '_', $prefix, split //, $suffix; $tainted_name =~ /^(.+)$/; my $name = $1; # run is(...) test with $name here

I'm wondering if not tainting the values returned by a non-filename glob() would be a useful enhancement to Perl. I throw this open for discussion.

— Ken


In reply to Should non-filename glob() results still be tainted? by kcott

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.