From 935c8b5875fadd80bb2c7c2fcf800bd0192aa3d2 Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Fri, 24 Nov 2017 09:17:20 +1100 Subject: [PATCH] Fixed bug #1758 : PHPCS gets stuck creating file list when processing circular symlinks --- package.xml | 1 + src/Filters/Filter.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/package.xml b/package.xml index 1a83948a43..a665409f1e 100644 --- a/package.xml +++ b/package.xml @@ -101,6 +101,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - Fixed bug #1731 : Directory exclusions do not work as expected when a single file name is passed to phpcs - Fixed bug #1746 : Very large reports can sometimes become garbled when using the parallel option - Fixed bug #1757 : Unknown type hint "object" in Squiz.Commenting.FunctionComment + - Fixed bug #1758 : PHPCS gets stuck creating file list when processing circular symlinks diff --git a/src/Filters/Filter.php b/src/Filters/Filter.php index c053c06b58..b7a6c2aa29 100644 --- a/src/Filters/Filter.php +++ b/src/Filters/Filter.php @@ -50,6 +50,15 @@ class Filter extends \RecursiveFilterIterator */ protected $ignoreFilePatterns = null; + /** + * A list of file paths we've already accepted. + * + * Used to ensure we aren't following circular symlinks. + * + * @var array + */ + protected $acceptedPaths = []; + /** * Constructs a filter. @@ -82,7 +91,18 @@ public function __construct($iterator, $basedir, Config $config, Ruleset $rulese public function accept() { $filePath = $this->current(); + $realPath = Util\Common::realpath($filePath); + if ($realPath !== false) { + // It's a real path somewhere, so record it + // to check for circular symlinks. + if (isset($this->acceptedPaths[$realPath]) === true) { + // We've been here before. + return false; + } + } + + $filePath = $this->current(); if (is_dir($filePath) === true) { if ($this->config->local === true) { return false; @@ -95,6 +115,7 @@ public function accept() return false; } + $this->acceptedPaths[$realPath] = true; return true; }//end accept() @@ -120,6 +141,7 @@ public function getChildren() // Set the ignore patterns so we don't have to generate them again. $children->ignoreDirPatterns = $this->ignoreDirPatterns; $children->ignoreFilePatterns = $this->ignoreFilePatterns; + $children->acceptedPaths = $this->acceptedPaths; return $children; }//end getChildren()