Bug 44157 - The return value of realpath should be tested
authorMarkAHershberger <mah@everybody.org>
Sat, 19 Jan 2013 20:20:29 +0000 (15:20 -0500)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 31 Jan 2013 04:53:22 +0000 (04:53 +0000)
Change-Id: Id178ee2fa5e294e858ee2af188e02c67f3205da9

includes/CryptRand.php
includes/WebStart.php
includes/filebackend/FSFileBackend.php

index fcf6a39..4255d56 100644 (file)
@@ -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
index 247f810..f209097 100644 (file)
@@ -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'] ) ) {
index a4e6ef6..a1d46c1 100644 (file)
@@ -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 ), '\\', '/' );
        }
 }