in reply to Apple, quoting, and system()
It's safer to pass system a list. The first element will be treated as the program name to fork, the rest are params to said program. Perhaps a concrete example is best:
Notice how 'ls /tmp; echo "GOT YA"' is parsed into two separate commands by the shell. By calling system in a safer way we can force everything in $dir to be treated as a filename.#!/usr/bin/perl -w use strict; # malicious input my $dir = '/tmp; echo "GOT YA"'; # system using shell print "AS STRING\n"; system("ls $dir"); # system w/o the shell print "\nAS LIST\n"; system('ls', $dir); =OUTPUT AS STRING [snip -- same as `ls /tmp`] GOT YA AS LIST ls: /tmp; echo "GOT YA": No such file or directory
-Blake
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re: Apple, quoting, and system()
by tye (Sage) on Nov 07, 2001 at 03:52 UTC |