[BUGFIX] Possible race condition when creating directory 37/33237/2
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:02:05 +0000 (22:02 +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/33237
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Utility/GeneralUtility.php

index c43f673..c7c0ec0 100644 (file)
@@ -2813,7 +2813,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);
                        }
                }