X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FGlobalFunctions.php;h=66e244082eb5fa96493f1368b103840f34e4a7f4;hb=99b84272c21b84c4861ef41f1078a5cd38689782;hp=537bdefe13748c62bdd0abafb2c29b2e87a7c981;hpb=2e6c378bcd76830ccc320369c4d7247d788ce825;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 537bdefe13..66e244082e 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -30,7 +30,6 @@ use MediaWiki\Session\SessionManager; // Hide compatibility functions from Doxygen /// @cond - /** * Compatibility functions * @@ -2134,6 +2133,24 @@ function wfTempDir() { return $tmp; } } + + /** + * PHP on Windows will detect C:\Windows\Temp as not writable even though PHP can write to it + * so create a directory within that called 'mwtmp' with a suffix of the user running the + * current process. + * The user is included as if various scripts are run by different users they will likely + * not be able to access each others temporary files. + */ + if ( wfIsWindows() ) { + $tmp = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mwtmp' . '-' . get_current_user(); + if ( !file_exists( $tmp ) ) { + mkdir( $tmp ); + } + if ( file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) { + return $tmp; + } + } + throw new MWException( 'No writable temporary directory could be found. ' . 'Please set $wgTmpDirectory to a writable directory.' ); } @@ -2439,6 +2456,15 @@ function wfShellExec( $cmd, &$retval = null, $environ = [], } wfDebug( "wfShellExec: $cmd\n" ); + // Don't try to execute commands that exceed Linux's MAX_ARG_STRLEN. + // Other platforms may be more accomodating, but we don't want to be + // accomodating, because very long commands probably include user + // input. See T129506. + if ( strlen( $cmd ) > SHELL_MAX_ARG_STRLEN ) { + throw new Exception( __METHOD__ . + '(): total length of $cmd must not exceed SHELL_MAX_ARG_STRLEN' ); + } + $desc = [ 0 => [ 'file', 'php://stdin', 'r' ], 1 => [ 'pipe', 'w' ], @@ -2473,14 +2499,6 @@ function wfShellExec( $cmd, &$retval = null, $environ = [], $eintr = defined( 'SOCKET_EINTR' ) ? SOCKET_EINTR : 4; $eintrMessage = "stream_select(): unable to select [$eintr]"; - // Build a table mapping resource IDs to pipe FDs to work around a - // PHP 5.3 issue in which stream_select() does not preserve array keys - // . - $fds = []; - foreach ( $pipes as $fd => $pipe ) { - $fds[(int)$pipe] = $fd; - } - $running = true; $timeout = null; $numReadyPipes = 0; @@ -2513,9 +2531,8 @@ function wfShellExec( $cmd, &$retval = null, $environ = [], break; } } - foreach ( $readyPipes as $pipe ) { + foreach ( $readyPipes as $fd => $pipe ) { $block = fread( $pipe, 65536 ); - $fd = $fds[(int)$pipe]; if ( $block === '' ) { // End of file fclose( $pipes[$fd] );