From e4ff0c75675144f1aefe61dcb49658e0cb9154e2 Mon Sep 17 00:00:00 2001 From: MarkAHershberger Date: Sat, 19 Jan 2013 15:20:29 -0500 Subject: [PATCH] Bug 44157 - The return value of realpath should be tested Change-Id: Id178ee2fa5e294e858ee2af188e02c67f3205da9 --- includes/CryptRand.php | 6 +++++- includes/WebStart.php | 10 +++++++--- includes/filebackend/FSFileBackend.php | 17 ++++++++++++----- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/includes/CryptRand.php b/includes/CryptRand.php index fcf6a3966b..4255d56f33 100644 --- a/includes/CryptRand.php +++ b/includes/CryptRand.php @@ -106,7 +106,11 @@ class MWCryptRand { } } // The absolute filename itself will differ from install to install so don't leave it out - $state .= realpath( $file ); + if( ( $path = realpath( $file ) ) !== false ) { + $state .= $path; + } else { + $state .= $file; + } $state .= implode( '', $stat ); } else { // The fact that the file isn't there is worth at least a diff --git a/includes/WebStart.php b/includes/WebStart.php index 247f810089..f209097956 100644 --- a/includes/WebStart.php +++ b/includes/WebStart.php @@ -80,11 +80,15 @@ define( 'MEDIAWIKI', true ); # Full path to working directory. # Makes it possible to for example to have effective exclude path in apc. -# Also doesn't break installations using symlinked includes, like -# __DIR__ would do. +# __DIR__ breaks symlinked includes, but realpath() returns false +# if we don't have permissions on parent directories. $IP = getenv( 'MW_INSTALL_PATH' ); if ( $IP === false ) { - $IP = realpath( '.' ); + if( realpath( '.' ) ) { + $IP = realpath( '.' ); + } else { + $IP = dirname( __DIR__ ); + } } if ( isset( $_SERVER['MW_COMPILED'] ) ) { diff --git a/includes/filebackend/FSFileBackend.php b/includes/filebackend/FSFileBackend.php index a4e6ef688c..a1d46c13d4 100644 --- a/includes/filebackend/FSFileBackend.php +++ b/includes/filebackend/FSFileBackend.php @@ -861,12 +861,15 @@ abstract class FSFileBackendList implements Iterator { * @param $params array */ public function __construct( $dir, array $params ) { - $dir = realpath( $dir ); // normalize - $this->suffixStart = strlen( $dir ) + 1; // size of "path/to/dir/" + $path = realpath( $dir ); // normalize + if( $path === false ) { + $path = $dir; + } + $this->suffixStart = strlen( $path ) + 1; // size of "path/to/dir/" $this->params = $params; try { - $this->iter = $this->initIterator( $dir ); + $this->iter = $this->initIterator( $path ); } catch ( UnexpectedValueException $e ) { $this->iter = null; // bad permissions? deleted? } @@ -958,8 +961,12 @@ abstract class FSFileBackendList implements Iterator { * @param $path string * @return string */ - protected function getRelPath( $path ) { - return strtr( substr( realpath( $path ), $this->suffixStart ), '\\', '/' ); + protected function getRelPath( $dir ) { + $path = realpath( $dir ); + if( $path === false ) { + $path = $dir; + } + return strtr( substr( $path, $this->suffixStart ), '\\', '/' ); } } -- 2.20.1