Correl Roush
08bc427e4a
git-svn-id: file:///srv/svn/scanner/trunk@19 a0501263-5b7a-4423-a8ba-1edf086583e7
36 lines
1.2 KiB
PHP
36 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() );
|
|
?>
|