Skip to content
Permalink
Browse files

Fix potential recursion

  • Loading branch information...
muglug committed Aug 6, 2019
1 parent 0051636 commit 14b37b95af2f32d7941432c4e59d1e4a79a417aa
@@ -995,7 +995,11 @@ function (Assertion $assertion) use ($found_generic_params) : Assertion {
$code_location = new CodeLocation($statements_analyzer->getSource(), $stmt);
$method_source = new TypeSource(
strtolower($method_id . '-' . $code_location->getShortSummary()),
strtolower(
$method_id
. '-' . $code_location->file_name
. ':' . $code_location->raw_file_start
),
new CodeLocation($source, $stmt->name)
);
} else {
@@ -2841,7 +2841,7 @@ private static function processTaintedness(
if ($function_is_pure) {
$codebase->taint->addSpecialization(
strtolower($cased_method_id . '#' . ($argument_offset + 1)),
$function_location->getShortSummary()
$function_location->file_name . ':' . $function_location->raw_file_start
);
$method_source = TypeSource::getForMethodArgument(
@@ -149,29 +149,49 @@ public function addSources(
}
}
public function getPredecessorPath(TypeSource $source) : string
/**
* @var array<string, bool> $visited_paths
*/
public function getPredecessorPath(TypeSource $source, array $visited_paths = []) : string
{
$source_descriptor = $source->id
. ($source->code_location ? ' (' . $source->code_location->getShortSummary() . ')' : '');
$location_summary = $source->code_location->getQuickSummary();
if (isset($visited_paths[$location_summary])) {
return '';
}
$visited_paths[$location_summary] = true;
$source_descriptor = $source->id . ($source->code_location ? ' (' . $location_summary . ')' : '');
if ($previous_source = $this->new_sources[$source->id] ?? self::$archived_sources[$source->id] ?? null) {
if ($previous_source === $source) {
throw new \UnexpectedValueException('bad');
}
return $this->getPredecessorPath($previous_source) . ' -> ' . $source_descriptor;
return $this->getPredecessorPath($previous_source, $visited_paths) . ' -> ' . $source_descriptor;
}
return $source_descriptor;
}
public function getSuccessorPath(TypeSource $source) : string
/**
* @var array<string, bool> $visited_paths
*/
public function getSuccessorPath(TypeSource $source, array $visited_paths = []) : string
{
$source_descriptor = $source->id
. ($source->code_location ? ' (' . $source->code_location->getShortSummary() . ')' : '');
$location_summary = $source->code_location->getQuickSummary();
if (isset($visited_paths[$location_summary])) {
return '';
}
$visited_paths[$location_summary] = true;
$source_descriptor = $source->id . ($source->code_location ? ' (' . $location_summary . ')' : '');
if ($next_source = $this->new_sinks[$source->id] ?? self::$archived_sinks[$source->id] ?? null) {
return $source_descriptor . ' -> ' . $this->getSuccessorPath($next_source);
return $source_descriptor . ' -> ' . $this->getSuccessorPath($next_source, $visited_paths);
}
return $source_descriptor;
@@ -27,7 +27,7 @@ public static function getForMethodArgument(
$function_id = $method_id . '#' . ($argument_offset + 1);
if ($function_location) {
$function_id .= '-' . $function_location->getShortSummary();
$function_id .= '-' . $function_location->file_name . ':' . $function_location->raw_file_start;
}
return new self(\strtolower($function_id), $code_location);
@@ -239,7 +239,7 @@ public function exec(string $sql) : void {}
public function testTaintedInputFromParam()
{
$this->expectException(\Psalm\Exception\CodeException::class);
$this->expectExceptionMessage('TaintedInput - somefile.php:8:32 - in path $_GET (somefile.php:4:41) -> a::getuserid (somefile.php:8:48) out path a::getappendeduserid (somefile.php:8:32) -> a::deleteuser#2 (somefile.php:13:49) -> pdo::exec#1 (somefile.php:17:36)');
$this->expectExceptionMessage('TaintedInput - somefile.php:8:32 - in path $_GET (somefile.php:4) -> a::getuserid (somefile.php:8) out path a::getappendeduserid (somefile.php:8) -> a::deleteuser#2 (somefile.php:13) -> pdo::exec#1 (somefile.php:17)');
$this->project_analyzer->trackTaintedInputs();
@@ -376,7 +376,7 @@ public function deleteUser(PDO $pdo, string $userId) : void {
public function testTaintedInputToParamAlternatePath()
{
$this->expectException(\Psalm\Exception\CodeException::class);
$this->expectExceptionMessage('TaintedInput - somefile.php:7:29 - in path $_GET (somefile.php:7:63) -> a::getappendeduserid#1 (somefile.php:11:62) -> a::getappendeduserid (somefile.php:7:36) out path a::deleteuser#3 (somefile.php:7:29) -> pdo::exec#1 (somefile.php:23:40)');
$this->expectExceptionMessage('TaintedInput - somefile.php:7:29 - in path -> a::getappendeduserid#1 (somefile.php:11) -> a::getappendeduserid (somefile.php:7) out path a::deleteuser#3 (somefile.php:7) -> pdo::exec#1 (somefile.php:23)');
$this->project_analyzer->trackTaintedInputs();
@@ -419,7 +419,7 @@ public function deleteUser(PDO $pdo, string $userId, string $userId2) : void {
public function testTaintedInParentLoader()
{
$this->expectException(\Psalm\Exception\CodeException::class);
$this->expectExceptionMessage('TaintedInput - somefile.php:24:47 - in path $_GET (somefile.php:28:39) -> c::foo#1 (somefile.php:23:48) out path agrandchild::loadfull#1 (somefile.php:24:47) -> a::loadpartial#1 (somefile.php:6:45) -> pdo::exec#1 (somefile.php:16:40)');
$this->expectExceptionMessage('TaintedInput - somefile.php:24:47 - in path $_GET (somefile.php:28) -> c::foo#1 (somefile.php:23) out path agrandchild::loadfull#1 (somefile.php:24) -> a::loadpartial#1 (somefile.php:6) -> pdo::exec#1 (somefile.php:16)');
$this->project_analyzer->trackTaintedInputs();

0 comments on commit 14b37b9

Please sign in to comment.
You can’t perform that action at this time.