From www.linuxfocus.org/English/September2001/article198.meta.shtml:
The general principle defining race conditions is the following : a process wants to access a system resource exclusively. It checks that the resource is not already used by another process, then uses it as it pleases. The race condition occurs when another process tries to use the same resource in the time-lag between the first process checking that resource and actually taking it over. The side effects may vary. The classical case in OS theory is the deadlock of both processes. More often it leads to application malfunction or even to security holes when a process wrongfully benefits from the privileges another.
In other words, using the above code:
while (-e $filename){
$filename.= '.new';
}
# while being here, another script can create a file with
# the same $filename, causing a bug...
open(F, "> $filename");
To be safe, you should 'lock' the resource and be sure that nothing else can use it. The practical solution is inside File::Temp, that is shipped with Perl since version 5.6.1 (I think)
Ciao, Valerio
|