Skip to content

Commit

Permalink
Merge pull request #8816 from weirdan/fix-8313
Browse files Browse the repository at this point in the history
Fixes #8313
  • Loading branch information
weirdan committed Dec 3, 2022
2 parents 35822f1 + 4d8af74 commit e64913c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
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',
],
];
}
}

0 comments on commit e64913c

Please sign in to comment.