From 04c6670f0c1b87ef594adf6fd89a06bedac7489a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 5 Dec 2012 23:23:01 +0100 Subject: [PATCH] Detect invalid ssh URLs, fixes #1124 --- src/Composer/Downloader/GitDownloader.php | 4 ++++ src/Composer/Repository/Vcs/GitDriver.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index beccd55ec..de465f3c4 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -265,6 +265,10 @@ class GitDownloader extends VcsDownloader { $handler = array($this, 'outputHandler'); + if (preg_match('{^ssh://[^@]+@[^:]+:[^0-9]+}', $url)) { + throw new \InvalidArgumentException('The source URL '.$url.' is invalid, ssh URLs should have a port number after ":".'."\n".'Use ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.'); + } + // public github, autoswitch protocols if (preg_match('{^(?:https?|git)(://github.com/.*)}', $url, $match)) { $protocols = $this->config->get('github-protocols'); diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index 8a6d8e42a..ee7489be9 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -45,6 +45,10 @@ class GitDriver extends VcsDriver throw new \RuntimeException('Can not clone '.$this->url.' to access package information. The "'.dirname($this->repoDir).'" directory is not writable by the current user.'); } + if (preg_match('{^ssh://[^@]+@[^:]+:[^0-9]+}', $this->url)) { + throw new \InvalidArgumentException('The source URL '.$this->url.' is invalid, ssh URLs should have a port number after ":".'."\n".'Use ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.'); + } + // update the repo if it is a valid git repository if (is_dir($this->repoDir) && 0 === $this->process->execute('git remote', $output, $this->repoDir)) { if (0 !== $this->process->execute('git remote update --prune origin', $output, $this->repoDir)) {