Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't crash when accessing immutable static property #8816

Merged
merged 1 commit into from Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -524,17 +524,19 @@ private static function taintProperty(
}
}

$stmt_var_type = $context->vars_in_scope[$var_id]->setParentNodes(
[$var_node->id => $var_node]
);
if (isset($context->vars_in_scope[$var_id])) {
$stmt_var_type = $context->vars_in_scope[$var_id]->setParentNodes(
[$var_node->id => $var_node]
);

if ($context->vars_in_scope[$var_id]->parent_nodes) {
foreach ($context->vars_in_scope[$var_id]->parent_nodes as $parent_node) {
$data_flow_graph->addPath($parent_node, $var_node, '=', $added_taints, $removed_taints);
if ($context->vars_in_scope[$var_id]->parent_nodes) {
foreach ($context->vars_in_scope[$var_id]->parent_nodes as $parent_node) {
$data_flow_graph->addPath($parent_node, $var_node, '=', $added_taints, $removed_taints);
}
}
}

$context->vars_in_scope[$var_id] = $stmt_var_type;
$context->vars_in_scope[$var_id] = $stmt_var_type;
}
}
} else {
if ($statements_analyzer->data_flow_graph instanceof TaintFlowGraph
Expand Down
15 changes: 15 additions & 0 deletions tests/UnusedCodeTest.php
Expand Up @@ -1742,6 +1742,21 @@ function f(): void {
',
'error_message' => 'UnevaluatedCode',
],
'noCrashOnReadonlyStaticProp' => [
'code' => '<?php
/** @psalm-immutable */
final class C { public int $val = 2; }

final class A {
private static C $prop;
public static function f()
{
self::$prop->val = 1;
}
}
',
'error_message' => 'InaccessibleProperty',
],
];
}
}