bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: best way to test for empty dir?


From: Greg Wooledge
Subject: Re: best way to test for empty dir?
Date: Fri, 11 Dec 2009 08:26:01 -0500
User-agent: Mutt/1.4.2.3i

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

[Prev in Thread] Current Thread [Next in Thread]