On Fri, Dec 11, 2009 at 01:09:09PM +0100, Antonio Macchi wrote:
> 
> this could be another way to accomplish this
> 
> empty_dir()  {
>   eval test \" $1/* \" == \"" $1/* "\";
> }
> 
> (excluding invisible files...)

This one also has the problem of failing if the directory contains a
single file named '*'.

It also blows up if you pass a specially crafted parameter,
e.g. /tmp/'"`date`"' due to lack of sanitizing $1 before calling eval.
Worse, it blows up if the *directory* contains specially crafted files
(such as '"`date`"') and there is *no* workaround for that short of
rewriting the whole thing.

imadev:~$ touch /tmp/sdf/'"`date 1>&2`"'
imadev:~$ empty_dir /tmp/sdf
Fri Dec 11 08:23:27 EST 2009

(Insert generic "now replace date with rm" advice.)


Reply via email to