Wizards: Do some input validation on repository URLs

Fixes: QTCREATORBUG-18935
Change-Id: Ie2103cbe2899ea23caaedd4a6350c78b5f380ab9
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Christian Kandeler
2019-07-23 16:15:57 +02:00
parent 00bdb007ee
commit df8ef72aec
13 changed files with 95 additions and 50 deletions

View File

@@ -3458,44 +3458,10 @@ void GitClient::StashInfo::end()
m_stashResult = NotStashed;
}
// GitRemote
GitRemote::GitRemote(const QString &url)
GitRemote::GitRemote(const QString &location) : Core::IVersionControl::RepoUrl(location)
{
static const QRegularExpression remotePattern(
"^(?:(?<protocol>[^:]+)://)?(?:(?<user>[^@]+)@)?(?<host>[^:/]+)"
"(?::(?<port>\\d+))?:?(?<path>.*)$");
if (url.isEmpty())
return;
// Check for local remotes (refer to the root or relative path)
// On Windows, local paths typically starts with <drive>:
auto startsWithWindowsDrive = [](const QString &url) {
if (!HostOsInfo::isWindowsHost() || url.size() < 2)
return false;
const QChar drive = url.at(0).toLower();
return drive >= 'a' && drive <= 'z' && url.at(1) == ':';
};
if (url.startsWith("file://") || url.startsWith('/') || url.startsWith('.')
|| startsWithWindowsDrive(url)) {
protocol = "file";
path = QDir::fromNativeSeparators(url.startsWith("file://") ? url.mid(7) : url);
if (isValid && protocol == "file")
isValid = QDir(path).exists() || QDir(path + ".git").exists();
return;
}
const QRegularExpressionMatch match = remotePattern.match(url);
if (!match.hasMatch())
return;
bool ok = false;
protocol = match.captured("protocol");
userName = match.captured("user");
host = match.captured("host");
port = match.captured("port").toUShort(&ok);
path = match.captured("path");
isValid = ok || match.captured("port").isEmpty();
}
} // namespace Internal

View File

@@ -29,6 +29,7 @@
#include "commitdata.h"
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/iversioncontrol.h>
#include <vcsbase/vcsbaseclient.h>
#include <utils/fileutils.h>
@@ -381,16 +382,10 @@ private:
QFutureSynchronizer<void> m_synchronizer; // for commit updates
};
class GitRemote {
class GitRemote : public Core::IVersionControl::RepoUrl
{
public:
GitRemote(const QString &url);
QString protocol;
QString userName;
QString host;
QString path;
quint16 port = 0;
bool isValid = false;
GitRemote(const QString &location);
};
} // namespace Internal

View File

@@ -163,6 +163,11 @@ Core::ShellCommand *GitVersionControl::createInitialCheckoutCommand(const QStrin
return command;
}
GitVersionControl::RepoUrl GitVersionControl::getRepoUrl(const QString &location) const
{
return GitRemote(location);
}
QStringList GitVersionControl::additionalToolsPath() const
{
QStringList res = m_client->settings().searchPathList();

View File

@@ -63,6 +63,8 @@ public:
const QString &localName,
const QStringList &extraArgs) final;
RepoUrl getRepoUrl(const QString &location) const override;
QStringList additionalToolsPath() const final;
void emitFilesChanged(const QStringList &);