Fix maintenance script failure when run as a child of a FastCGI worker
authorTim Starling <tstarling@wikimedia.org>
Fri, 8 Dec 2017 04:34:23 +0000 (15:34 +1100)
committerTim Starling <tstarling@wikimedia.org>
Fri, 8 Dec 2017 04:34:23 +0000 (15:34 +1100)
Use PHP_SAPI==cli instead of checking $_SERVER['REQUEST_METHOD'],
since $_SERVER is populated from the environment when running HHVM in
CLI mode. Environment variables set by a FastCGI worker thus leak
through to child processes run via the shell, and cause this check to
fail.

When I wrote this check in March 2004 (r2803), I didn't know about
PHP_SAPI. Checking PHP_SAPI is quite sufficient to prevent web execution,
we use it in other places.

Bug: T111441
Change-Id: Iad8469ee25df4b0e0c2371e7975a300b1695dd8d

maintenance/Maintenance.php

index 255892b..a3e0ffd 100644 (file)
@@ -662,7 +662,7 @@ abstract class Maintenance {
                global $IP, $wgCommandLineMode, $wgRequestTime;
 
                # Abort if called from a web server
-               if ( isset( $_SERVER ) && isset( $_SERVER['REQUEST_METHOD'] ) ) {
+               if ( PHP_SAPI !== 'cli' ) {
                        $this->fatalError( 'This script must be run from the command line' );
                }