Skip to content

Commit

Permalink
Fix a Http2 bug which cause crash in some case
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlst committed Feb 13, 2020
1 parent 41284ad commit f05271e
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 44 deletions.
3 changes: 2 additions & 1 deletion dist/add-ons/webcachemgr/src/Panel/ControlPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class ControlPanel
/**
* @var string
*/
const PANEL_API_VERSION = '1.9.7';
const PANEL_API_VERSION = '1.9.8';

/**
* @since 1.9
Expand Down Expand Up @@ -816,6 +816,7 @@ public static function meetsMinAPIVerRequirement()
public static function checkPanelAPICompatibility( $panelAPIVer )
{
$supportedAPIVers = array (
'1.9.8',
'1.9.7',
'1.9.6.1',
'1.9.6',
Expand Down
130 changes: 90 additions & 40 deletions dist/add-ons/webcachemgr/src/WPCaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,85 @@ public function massDashDisable( $extraArgs )
return $ret;
}

/**
* Set 'REQUEST_URI' global server and environment variables.
*
* @since 1.9.8
*
* @param string $key
* @param mixed $val
*/
private function setEnvVar( $key, $val )
{
$key = 'REQUEST_URI';

$_SERVER[$key] = $val;
putenv("{$key}={$val}");
}

/**
* Checks if the current WordPress installation is a multisite install and
* does some pre-load setup if so.
*
* Patterns and multisite check logic based on WordPress function
* is_multisite().
*
* @since 1.9.8
*
* @return boolean
* @throws LSCMException
*/
private function isMultisite()
{
$isMultiSite = false;

$pattern1 = '/define\(\s*[\'"]MULTISITE[\'"]\s*,[^;]*;/';
$pattern2 = '/define\(\s*[\'"]MULTISITE[\'"]\s*,\s*true\s*\)\s*;/';
$pattern3 = '/define\(\s*[\'"]SUBDOMAIN_INSTALL[\'"]\s*,[^;]*;/';
$pattern4 = '/define\(\s*[\'"]VHOST[\'"]\s*,[^;]*;/';
$pattern5 = '/define\(\s*[\'"]SUNRISE[\'"]\s*,[^;]*;/';

$config_content =
file_get_contents($this->currInstall->getWpConfigFile());

if ( preg_match($pattern1, $config_content, $m1)
&& preg_match($pattern2, $m1[0]) ) {

$isMultiSite = true;
}
elseif ( preg_match($pattern3, $config_content)
|| preg_match($pattern4, $config_content)
|| preg_match($pattern5, $config_content) ) {

$isMultiSite = true;
}

if ( $isMultiSite ) {

if ( !preg_match('/define\(\s*[\'"]DOMAIN_CURRENT_SITE[\'"]\s*,\s*[\'"](.+)[\'"]\s*\)\s*;/',
$config_content, $m2) ) {

throw new LSCMException(
'Cannot find DOMAIN_CURRENT_SITE with MULTISITE defined.');
}

$this->currInstall->setServerName($m2[1]);

if ( !preg_match('/define\(\s*[\'"]PATH_CURRENT_SITE[\'"]\s*,\s*[\'"](.+)[\'"]\s*\)\s*;/',
$config_content, $m3) ) {

throw new LSCMException(
'Cannot find PATH_CURRENT_SITE with MULTISITE defined.');
}

$this->setEnvVar('REQUEST_URI', $m3[1]);

define('WP_NETWORK_ADMIN', true);
}

return $isMultiSite;
}

private function initWp()
{
/**
Expand Down Expand Up @@ -1174,36 +1253,10 @@ private function initWp()
*/
$_SERVER['SCRIPT_FILENAME'] = "{$wpPath}/wp-admin/plugins.php";

$config_content =
file_get_contents($this->currInstall->getWpConfigFile());
$uri = '';

if ( preg_match('/define\(\s*[\'"]MULTISITE[\'"]\s*,\s*true\s*\)\s*;/', $config_content) ) {

if ( !preg_match('/define\(\s*[\'"]DOMAIN_CURRENT_SITE[\'"]\s*,\s*[\'"](.+)[\'"]\s*\)\s*;/',
$config_content, $m) ) {

throw new LSCMException(
'Cannot find DOMAIN_CURRENT_SITE with MULTISITE defined.');
}

$this->currInstall->setServerName($m[1]);

if ( !preg_match('/define\(\s*[\'"]PATH_CURRENT_SITE[\'"]\s*,\s*[\'"](.+)[\'"]\s*\)\s*;/',
$config_content, $m2) ) {

throw new LSCMException(
'Cannot find PATH_CURRENT_SITE with MULTISITE defined.');
}

$uri = $m2[1];

define('WP_NETWORK_ADMIN', true);
if ( ! $this->isMultisite() ) {
$this->setEnvVar('REQUEST_URI', '');
}

$_SERVER['REQUEST_URI'] = $uri;
putenv("REQUEST_URI={$uri}");

/**
* Set for LSCWP v1.1.5.1+ plugin logic.
*/
Expand All @@ -1212,23 +1265,20 @@ private function initWp()
/**
* For enable/disable.
*/
$_SERVER['DOCUMENT_ROOT'] = $docRoot;
putenv("DOCUMENT_ROOT={$docRoot}");
$this->setEnvVar('DOCUMENT_ROOT', $docRoot);
}

if ( $serverName = $this->currInstall->getServerName() ) {
$serverName = $this->currInstall->getServerName();

/**
* For security plugins.
*/
$_SERVER['HTTP_HOST'] = $serverName;
putenv("HTTP_HOST={$serverName}");
}
else {
$_SERVER['HTTP_HOST'] = self::LSCWP_HTTP_HOST_TEST;
putenv('HTTP_HOST=' . self::LSCWP_HTTP_HOST_TEST);
if ( empty($serverName) ) {
$serverName = self::LSCWP_HTTP_HOST_TEST;
}

/**
* For security plugins.
*/
$this->setEnvVar('HTTP_HOST', $serverName);

/**
* Version specific includes may fail on RC releases.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/lshttpdmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
/***
* Do not change the below format, it will be set correctly while packing the code
*/
#define BUILDTIME " (built: Mon Feb 10 19:58:51 UTC 2020)"
#define BUILDTIME " (built: Thu Feb 13 15:07:51 UTC 2020)"

#define GlobalServerSessionHooks (LsiApiHooks::getServerSessionHooks())

Expand Down
4 changes: 2 additions & 2 deletions src/spdy/h2stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void H2Stream::continueRead()
{
LS_DBG_L(this, "H2Stream::continueRead()");
setFlag(HIO_FLAG_WANT_READ, 1);
if (m_bufIn.size() > 0)
if (getHandler() && m_bufIn.size() > 0)
getHandler()->onReadEx();
}

Expand All @@ -210,7 +210,7 @@ void H2Stream:: continueWrite()

int H2Stream::onTimer()
{
if (getState() == HIOS_CONNECTED)
if (getHandler() && getState() == HIOS_CONNECTED)
return getHandler()->onTimerEx();
return 0;
}
Expand Down

0 comments on commit f05271e

Please sign in to comment.