From 1a391b572cc82b681ce9f52b6db6aa87718fb137 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 30 Jul 2019 09:18:19 +0200 Subject: [PATCH] Prevent require command from allowing a package to require itself, fixes #8247 --- src/Composer/Command/RequireCommand.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index 9b12941b8..8f91b6675 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -145,7 +145,12 @@ EOT // validate requirements format $versionParser = new VersionParser(); - foreach ($requirements as $constraint) { + foreach ($requirements as $package => $constraint) { + if (strtolower($package) === $composer->getPackage()->getName()) { + $io->writeError(sprintf('Root package \'%s\' cannot require itself in its composer.json', $package)); + + return 1; + } $versionParser->parseConstraints($constraint); }