Skip to content

Commit

Permalink
Improvements with disabled functions for app engine partial disables
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Aug 21, 2014
1 parent ba89e4d commit 4136bb6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,43 @@ public static function findCommand($cmd)
/**
* Check to see if a function has been disabled through php.ini
*
* @param string $function function name to verify
* @param string $function function name to verify
* @param mixed $enabledFunctions known enabled functions
*
* @return bool
*/
public static function isFunctionDisabled($function)
public static function isFunctionDisabled($function, $enabledFunctions = null)
{
return in_array($function, explode(',', ini_get('disable_functions')));
$disabledFunctions = explode(',', ini_get('disable_functions'));
if(self::isAppEngine())
{
if($enabledFunctions === null)
{
$enabledFunctions = ini_get('google_app_engine.enable_functions');
}
$aeDisabled = array_diff(
[
'gc_collect_cycles',
'gc_enable',
'gc_disable',
'gc_enabled',
'getmypid',
'getmyuid',
'getmygid',
'getrusage',
'getmyinode',
'get_current_user',
'libxml_disable_entity_loader',
'parse_str',
'phpinfo',
'phpversion',
'php_uname',
'php_sapi_name'
],
ValueAs::arr($enabledFunctions)
);
$disabledFunctions = array_merge($disabledFunctions, $aeDisabled);
}
return in_array($function, $disabledFunctions);
}
}
15 changes: 15 additions & 0 deletions tests/SystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,19 @@ public function testDisabledFunctionCheck()

$this->assertFalse(\Packaged\Helpers\System::isFunctionDisabled('echo'));
}

public function testAppEngineDisabledFunctions()
{
$test = $_SERVER['SERVER_SOFTWARE'];
$_SERVER['SERVER_SOFTWARE'] = 'Google App Engine/1.9.6';
$this->assertTrue(\Packaged\Helpers\System::isAppEngine());
$this->assertTrue(\Packaged\Helpers\System::isFunctionDisabled('phpinfo'));
$this->assertFalse(
\Packaged\Helpers\System::isFunctionDisabled(
'phpinfo',
'phpinfo,parse_str'
)
);
$_SERVER['SERVER_SOFTWARE'] = $test;
}
}

0 comments on commit 4136bb6

Please sign in to comment.