Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added multi-arg-open CS

...

This compliant solution again sanitizes the untrusted user input. However, it uses the multi-arg form of open().

Code Block
bgColor#ccccff
langperl
my $file;

...


my $dir = $ARGV[0];

...


croak "Argument contains unsanitary characters, stopped" if ($dir =~ m|[^-A-Za-z0-9_/.~]|);

...


open( my $listing, "-|", "ls", "-F", $dir) or croak "error executing command: stopped";

...


while (<$listing>) {

...


  print "Result: $_";

...


}

...


close( $listing);

The perlfunc manpages states, regarding all but the first two arguments to open():

...