Last modified: 2011-02-23 12:35:56 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T22244, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 20244 - Installer does not validate SQLite database directory for stable path
Installer does not validate SQLite database directory for stable path
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Installer (Other open bugs)
unspecified
All All
: Normal enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks: sqlite
  Show dependency treegraph
 
Reported: 2009-08-14 16:27 UTC by Brion Vibber
Modified: 2011-02-23 12:35 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Brion Vibber 2009-08-14 16:27:57 UTC
The SQLite database directory isn't being clearly validated; if you type in something like "foobar.sqlite" the installer will appear to complete but the site won't work -- you'll end up with a 'foobar.sqlite' subdirectory *inside* the 'config' folder, which you may not even have file permissions to move or rename.

The relative path of course then can't be reached from the main index.php running MediaWiki, and your site fails.

If a relative path is given, it should be rebased against $IP.
Comment 2 Brion Vibber 2009-08-14 17:01:35 UTC
Listing the default in the installer might be good too. :) And we might need/want to expose wgSQLiteDataDirMode or set it more appropriately...
Comment 3 Chad H. 2011-01-25 21:13:00 UTC
Max, would you mind looking at this? 

I know we already expose the directory path in the new installer (the mode setting was useless and removed awhile ago)
Comment 4 Max Semenik 2011-01-26 18:14:52 UTC
As the matter of fact, we're already attempting to make the path absolute, but since we call realpath() before attempting to create the directory, it may fail. Here's my fix for it, I can't currently commit it myself.

Index: SqliteInstaller.php
===================================================================
--- SqliteInstaller.php	(revision 77580)
+++ SqliteInstaller.php	(working copy)
@@ -45,16 +45,30 @@
 			$this->getTextBox( 'wgDBname', 'config-db-name', array(), $this->parent->getHelpBox( 'config-sqlite-name-help' ) );
 	}
 
+	/*
+	 * Safe wrapper for PHP's realpath() that fails gracefully if it's unable to canonicalize the path.
+	 */
+	private static function realpath( $path ) {
+		$result = realpath( $path );
+		if ( !$result ) {
+			return $path;
+		}
+		return $result;
+	}
+
 	public function submitConnectForm() {
 		$this->setVarsFromRequest( array( 'wgSQLiteDataDir', 'wgDBname' ) );
 
-		$dir = realpath( $this->getVar( 'wgSQLiteDataDir' ) );
-		if ( !$dir ) {
-			// realpath() sometimes fails, especially on Windows
-			$dir = $this->getVar( 'wgSQLiteDataDir' );
+		# Try realpath() if the directory already exists
+		$dir = self::realpath( $this->getVar( 'wgSQLiteDataDir' ) );
+		$result = self::dataDirOKmaybeCreate( $dir, true /* create? */ );
+		if ( $result->isOK() )
+		{
+			# Try expanding again in case we've just created it
+			$dir = self::realpath( $dir );
+			$this->setVar( 'wgSQLiteDataDir', $dir );
 		}
-		$this->setVar( 'wgSQLiteDataDir', $dir );
-		return self::dataDirOKmaybeCreate( $dir, true /* create? */ );
+		return $result;
 	}
 
 	private static function dataDirOKmaybeCreate( $dir, $create = false ) {
Comment 5 Brion Vibber 2011-01-26 18:55:33 UTC
If the path can't be canonicalized, that sounds...... bad. What sort of failure are you referring to exactly, and why is it failing?
Comment 6 Max Semenik 2011-01-26 19:03:47 UTC
From PHP docs: "realpath() returns FALSE on failure, e.g. if the file does not exist."
I also observed it failing on Windows with paths containing spaces.
Comment 7 Brion Vibber 2011-01-26 19:04:51 UTC
We just figured out the not-existing-yet one on IRC. :D I'll take a quick peek at the Windows case.
Comment 8 Max Semenik 2011-02-23 12:35:56 UTC
Meh, committed in r82660.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links