From 3d9c4a371873f14ade115719b1ba2ed26fff71af Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Thu, 15 Nov 2018 19:28:56 +0100 Subject: [PATCH] [Bridge] Improve working directory handling - Initialize with null to prevent leaking configurations - Check if the working directory is a directory - Store the real path instead of raw data - Add final path separator as expected by Bridge::create --- lib/Bridge.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Bridge.php b/lib/Bridge.php index 3ac88768..3c6efabd 100644 --- a/lib/Bridge.php +++ b/lib/Bridge.php @@ -43,9 +43,9 @@ class Bridge { * Do not access this property directly! * Use {@see Bridge::setWorkingDir()} and {@see Bridge::getWorkingDir()} instead. * - * @var string + * @var string|null */ - protected static $workingDir; + protected static $workingDir = null; /** * Holds a list of whitelisted bridges. @@ -104,9 +104,12 @@ class Bridge { * @param string $dir Path to the directory containing bridges. * @throws \LogicException if the provided path is not a valid string. * @throws \Exception if the provided path does not exist. + * @throws \InvalidArgumentException if $dir is not a directory. * @return void */ public static function setWorkingDir($dir){ + self::$workingDir = null; + if(!is_string($dir)) { throw new \InvalidArgumentException('Working directory is not a valid string!'); } @@ -115,7 +118,11 @@ class Bridge { throw new \Exception('Working directory does not exist!'); } - self::$workingDir = $dir; + if(!is_dir($dir)) { + throw new \InvalidArgumentException('Working directory is not a directory!'); + } + + self::$workingDir = realpath($dir) . '/'; } /**