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

[WIP] [PhingTask] Fixed possible infinity loop #1294

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion classes/phing/tasks/system/PhingTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,34 @@ private function processFile(): void
$this->newTarget = $this->newProject->getDefaultTarget();
}

$owningTargetName = $this->getOwningTarget()->getName();
// Are we trying to call the target in which we are defined?
if (
$this->newProject->getBaseDir() == $this->project->getBaseDir()
&& $this->newProject->getProperty("phing.file") == $this->project->getProperty("phing.file")
&& $this->getOwningTarget() !== null
&& $this->newTarget == $this->getOwningTarget()->getName()
&& $this->newTarget == $owningTargetName
) {
throw new BuildException("phing task calling its own parent target");
}

$targets = $this->getProject()->getTargets();
$taskName = $this->getTaskName();
array_walk(
$targets,
static function (Target $target) use ($owningTargetName, $taskName) {
if (in_array($owningTargetName, $target->getDependencies())) {
throw new BuildException(
sprintf(
"%s task calling a target that depends on its parent target '%s'.",
$taskName,
$owningTargetName
)
);
}
}
);

$this->addReferences();
$this->newProject->executeTarget($this->newTarget);
} catch (Exception $e) {
Expand Down
8 changes: 8 additions & 0 deletions test/classes/phing/tasks/condition/PhingTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ public function testOverrideWinsNoInheritAll()
$this->expectLogContaining('test-property-override-no-inheritall-start', 'The value of test is 4');
}

/**
* Fail due to infinite recursion loop
*/
public function testInfiniteLoopViaDepends(): void
{
$this->expectBuildException('infinite-loop-via-depends', 'infinite loop');
}

public function testMultiSameProperty(): void
{
$this->expectLogContaining('multi-same-property', 'prop is two');
Expand Down