From: Benjamin Eberlei <kontakt@beberlei.de>
Date: Mon, 31 Aug 2015 13:54:27 +0200
Subject: [DCOM-293] Fix security misconfiguration vulnerability that can
 allow local arbitrary code execution.

Origin: upstream, https://github.com/doctrine/annotations/commit/f25c8aab83e0c3e976fd7d19875f198ccf2f7535
---
 lib/Doctrine/Common/Annotations/FileCacheReader.php | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/lib/Doctrine/Common/Annotations/FileCacheReader.php b/lib/Doctrine/Common/Annotations/FileCacheReader.php
index e9b29af..f4ac5f2 100644
--- a/lib/Doctrine/Common/Annotations/FileCacheReader.php
+++ b/lib/Doctrine/Common/Annotations/FileCacheReader.php
@@ -53,6 +53,11 @@ class FileCacheReader implements Reader
     private $classNameHashes = array();
 
     /**
+     * @var int
+     */
+    private $umask;
+
+    /**
      * Constructor.
      *
      * @param Reader  $reader
@@ -61,10 +66,19 @@ class FileCacheReader implements Reader
      *
      * @throws \InvalidArgumentException
      */
-    public function __construct(Reader $reader, $cacheDir, $debug = false)
+    public function __construct(Reader $reader, $cacheDir, $debug = false, $umask = 0002)
     {
+        if ( ! is_int($umask)) {
+            throw new \InvalidArgumentException(sprintf(
+                'The parameter umask must be an integer, was: %s',
+                gettype($umask)
+            ));
+        }
+
         $this->reader = $reader;
-        if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true)) {
+        $this->umask = $umask;
+
+        if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777 & (~$this->umask), true)) {
             throw new \InvalidArgumentException(sprintf('The directory "%s" does not exist and could not be created.', $cacheDir));
         }
 
