Skip to content

Commit

Permalink
Taint through reset call
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Mar 28, 2021
1 parent f24ef25 commit f41deea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use PhpParser;
use Psalm\Plugin\EventHandler\Event\FunctionReturnTypeProviderEvent;
use Psalm\Internal\Analyzer\Statements\Expression\Fetch\ArrayFetchAnalyzer;
use Psalm\Type;

class ArrayPointerAdjustmentReturnTypeProvider implements \Psalm\Plugin\EventHandler\FunctionReturnTypeProviderInterface
Expand Down Expand Up @@ -77,6 +78,14 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
}
}

ArrayFetchAnalyzer::taintArrayFetch(
$statements_source,
$first_arg,
null,
$value_type,
Type::getMixed()
);

return $value_type;
}
}
11 changes: 11 additions & 0 deletions tests/TaintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2122,6 +2122,17 @@ function doTheMagic(array $values) {}
doTheMagic([(string)$_GET["bad"] => "foo"]);',
'error_message' => 'TaintedHtml',
],
'taintThroughReset' => [
'<?php
function foo(array $arr) : void {
if ($arr) {
echo reset($arr);
}
}
foo([$_GET["a"]]);',
'error_message' => 'TaintedHtml',
],
/*
// TODO: Stubs do not support this type of inference even with $this->message = $message.
// Most uses of getMessage() would be with caught exceptions, so this is not representative of real code.
Expand Down

0 comments on commit f41deea

Please sign in to comment.