[BUGFIX] Possible race condition when creating directory 81/32881/6
authorBernhard Kraft <kraft@webconsulting.at>
Fri, 19 Sep 2014 08:58:36 +0000 (10:58 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Thu, 9 Oct 2014 20:01:37 +0000 (22:01 +0200)
During various actions in the backend which require a cache directory
in typo3temp/ a race condition can occur while creating the directory.
The race condition is caused by GeneralUtility::createDirectoryPath.

There is a check whether the directory to be created already exists.
Later the directory is created using mkdir(). If in the meantime
another process creates the directory the exception will get thrown.

Resolves: #47269
Releases: master, 6.2
Change-Id: Iff46addd9ad6d738d1760f82a436dec9840c331d
Reviewed-on: http://review.typo3.org/32881
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Utility/GeneralUtility.php

index 139d7f8..7a4e764 100644 (file)
@@ -2801,7 +2801,8 @@ Connection: close
                                $currentPath = substr($currentPath, 0, $separatorPosition);
                        } while (!is_dir($currentPath) && $separatorPosition !== FALSE);
                        $result = @mkdir($fullDirectoryPath, $permissionMask, TRUE);
-                       if (!$result) {
+                       // Check existence of directory again to avoid race condition. Directory could have get created by another process between previous is_dir() and mkdir()
+                       if (!$result && !@is_dir($fullDirectoryPath)) {
                                throw new \RuntimeException('Could not create directory "' . $fullDirectoryPath . '"!', 1170251401);
                        }
                }