[Top][All Lists]

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

Re: Recursively calling a bash script goes undetected and eats all syste

From: Bob Proulx
Subject: Re: Recursively calling a bash script goes undetected and eats all system memory
Date: Thu, 9 Dec 2010 14:11:55 -0700
User-agent: Mutt/1.5.20 (2009-06-14)

Diggory Hardy wrote:
> With a simple script such as that below, bash can enter an infinite
> loop of eating memory until the system is rendered unusable:
> #!/bin/bash
> PATH=~
> infinitely-recurse

Yes, of course.  It calls itself repeatedly and every copy consumes
just a little more system resources until they are all consumed.

> Save this as infinitely-recurse in your home directory and run - and
> make sure you kill it pretty quick.

This is a simpler variation on the classic fork bomb.


> OK, so an obvious bug when put like this, though it bit me recently
> (mistakenly using PATH as an ordinary variable and having a script

Have you ever cut yourself on a kitchen knife?  I am sure the answer
is yes because we all have at one time or another.  As a thought
experiment design a kitchen knife in which it would be impossible to
cut yourself.  Take some time to think about it.  You could install
some type of safety guard.  You could use some type of box.  Perhaps
some pull cords to keep hands back in some way.

Now is the important question.  After having designed the safe kitchen
knife that wil prevent you from ever cutting yourself would you
actually use such a knife yourself?

> with the same name as a system program). Would it not be simple to
> add some kind of protection against this — say don't let a script
> call itself more than 100 times?

Detecting and avoiding this is actually not a simple thing to do at
all.  This is really a much harder problem than you think it is and
isn't something that can be fixed in bash.  The best result is simply
learning to avoid the problem.


reply via email to

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