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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |