2020-06-25 23:17:08 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Internal\Analyzer\Statements\Expression;
|
|
|
|
|
|
|
|
use PhpParser;
|
|
|
|
use Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer;
|
|
|
|
use Psalm\Internal\Analyzer\Statements\Expression\Call\ArgumentAnalyzer;
|
|
|
|
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
2020-10-13 22:49:03 +02:00
|
|
|
use Psalm\Internal\DataFlow\TaintSink;
|
2020-09-30 18:28:13 +02:00
|
|
|
use Psalm\Internal\Codebase\TaintFlowGraph;
|
2020-06-25 23:17:08 +02:00
|
|
|
use Psalm\CodeLocation;
|
|
|
|
use Psalm\Context;
|
|
|
|
use Psalm\Storage\FunctionLikeParameter;
|
|
|
|
use Psalm\Type;
|
|
|
|
use Psalm\Type\Atomic\TInt;
|
|
|
|
use Psalm\Type\Atomic\TString;
|
|
|
|
|
|
|
|
class ExitAnalyzer
|
|
|
|
{
|
|
|
|
public static function analyze(
|
|
|
|
StatementsAnalyzer $statements_analyzer,
|
|
|
|
PhpParser\Node\Expr\Exit_ $stmt,
|
|
|
|
Context $context
|
|
|
|
) : bool {
|
|
|
|
if ($stmt->expr) {
|
|
|
|
$context->inside_call = true;
|
|
|
|
|
|
|
|
if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context) === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-13 23:28:12 +02:00
|
|
|
if ($statements_analyzer->data_flow_graph instanceof TaintFlowGraph) {
|
2020-06-25 23:17:08 +02:00
|
|
|
$call_location = new CodeLocation($statements_analyzer->getSource(), $stmt);
|
|
|
|
|
2020-09-21 05:59:52 +02:00
|
|
|
$echo_param_sink = TaintSink::getForMethodArgument(
|
2020-06-25 23:17:08 +02:00
|
|
|
'exit',
|
|
|
|
'exit',
|
|
|
|
0,
|
|
|
|
null,
|
|
|
|
$call_location
|
|
|
|
);
|
|
|
|
|
|
|
|
$echo_param_sink->taints = [
|
|
|
|
Type\TaintKind::INPUT_HTML,
|
|
|
|
Type\TaintKind::USER_SECRET,
|
|
|
|
Type\TaintKind::SYSTEM_SECRET
|
|
|
|
];
|
|
|
|
|
2020-10-13 23:28:12 +02:00
|
|
|
$statements_analyzer->data_flow_graph->addSink($echo_param_sink);
|
2020-06-25 23:17:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($expr_type = $statements_analyzer->node_data->getType($stmt->expr)) {
|
|
|
|
$exit_param = new FunctionLikeParameter(
|
|
|
|
'var',
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
if (ArgumentAnalyzer::verifyType(
|
|
|
|
$statements_analyzer,
|
|
|
|
$expr_type,
|
|
|
|
new Type\Union([new TInt(), new TString()]),
|
|
|
|
null,
|
|
|
|
'exit',
|
|
|
|
0,
|
|
|
|
new CodeLocation($statements_analyzer->getSource(), $stmt->expr),
|
|
|
|
$stmt->expr,
|
|
|
|
$context,
|
|
|
|
$exit_param,
|
|
|
|
false,
|
|
|
|
null,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
new CodeLocation($statements_analyzer, $stmt)
|
|
|
|
) === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$context->inside_call = false;
|
|
|
|
}
|
|
|
|
|
2020-11-09 14:44:03 +01:00
|
|
|
$statements_analyzer->node_data->setType($stmt, \Psalm\Type::getEmpty());
|
|
|
|
|
2020-06-25 23:17:08 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|