37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
|
<?php
|
||
|
class VariableModule extends ScannerModule {
|
||
|
private $assigned_variables = array();
|
||
|
private $captured = array();
|
||
|
|
||
|
function VariableModule() {
|
||
|
$this->ScannerModule();
|
||
|
}
|
||
|
function parserCallback( $object ) {
|
||
|
$pattern = '/\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/';
|
||
|
$matches = array();
|
||
|
$scope = "{$object['in_class']}::{$object['in_function']}";
|
||
|
if (!isset($this->assigned_variables[$scope] ) )
|
||
|
$this->assigned_variables[$scope] = array();
|
||
|
if ($object['type'] == PHPPARSER_ASSIGNMENT) {
|
||
|
//$this->fault($object, 0, "Assignment: {$object['name']}");
|
||
|
list($variable, $value) = explode('=', $object['name']);
|
||
|
$this->assigned_variables[$scope][] = $variable;
|
||
|
}
|
||
|
if (
|
||
|
$object['type'] == PHPPARSER_VARIABLE
|
||
|
// Cannot yet accurately scan the global scope, so functions only
|
||
|
&& !empty($object['in_function'])
|
||
|
&& !in_array($object['name'], $this->assigned_variables[$scope])
|
||
|
&& !in_array($object['name'], array(
|
||
|
// Superglobals are exempt, obviously
|
||
|
'$GLOBALS', '$_SERVER', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_REQUEST', '$_ENV'
|
||
|
))
|
||
|
) {
|
||
|
$this->fault($object, FAULT_MEDIUM, "Undefined Variable: {$object['name']}");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
addModule( new VariableModule() );
|
||
|
?>
|