From: Tim Starling Date: Thu, 21 Jan 2016 05:35:59 +0000 (+1100) Subject: Improve wfTempDir() fallback sequence X-Git-Tag: 1.31.0-rc.0~8263 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=b7e65e555adc2b77dad55eb2b28338bf2e7619e1;hp=1dd4c867e5368cfd187a9eb2f141440a5a8ce86f;p=lhc%2Fweb%2Fwiklou.git Improve wfTempDir() fallback sequence Validate the return value of sys_get_temp_dir(), and use upload_tmp_dir if that is not writable. If nothing is writable, throw an exception. Bug: T119934 Change-Id: I27d784f55c47277bbab1192853e2e04a9d8bd39a --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index f797e5b5d7..928066b005 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2162,8 +2162,8 @@ function wfIsHHVM() { /** * Tries to get the system directory for temporary files. First * $wgTmpDirectory is checked, and then the TMPDIR, TMP, and TEMP - * environment variables are then checked in sequence, and if none are - * set try sys_get_temp_dir(). + * environment variables are then checked in sequence, then + * sys_get_temp_dir(), then upload_tmp_dir from php.ini. * * NOTE: When possible, use instead the tmpfile() function to create * temporary files to avoid race conditions on file creation, etc. @@ -2178,13 +2178,16 @@ function wfTempDir() { } $tmpDir = array_map( "getenv", array( 'TMPDIR', 'TMP', 'TEMP' ) ); + $tmpDir[] = sys_get_temp_dir(); + $tmpDir[] = ini_get( 'upload_tmp_dir' ); foreach ( $tmpDir as $tmp ) { if ( $tmp && file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) { return $tmp; } } - return sys_get_temp_dir(); + throw new MWException( 'No writable temporary directory could be found. ' . + 'Please set $wgTmpDirectory to a writable directory.' ); } /**