Race condition in XF\Util\File::createTempDir

Xon

Well-known member
Affected version
2.2.9
The XF\Util\File::createTempDir function has a race condition where the same directory can be attempted to be created multiple times if enough requests happen at once.

This causes createDirectory to throw as it fails to create the directory, resulting in unexpected errors, so at least this doesn't cause anonymous data conflicts.
 

FTL

Well-known member
Interesting bug. I'd never have expected to see a race condition in software like this. I wonder if the devs will be able to replicate it.
 

Xon

Well-known member
uniqid really isn't unique enough for this purpose, and there are other places in the code which likely need fixing.
 

K a M a L

Active member
Even if a "unique enough" random string generator is used .. it is always a good practice to use
Code:
if (!mkdir($partialPath) && !is_dir($partialPath))
{
   return false;
}
instead of
Code:
if (!mkdir($partialPath))
{
   return false;
}

to avoid race condition that could occur when another process creates the required directory while current process is trying to do
 
Top