From e79d68dab6876d34fdbee071175913a90272ab31 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 22 Sep 2018 23:01:39 +0200 Subject: [PATCH] Git: Improve local file detection in GitRemote * Make sure url has a proper size before accessing its elements * Also check for valid drive letter before ':' Change-Id: I958cbd492caa8a6ad4a5bf424277d8287f8cf0d4 Reviewed-by: Orgad Shaneh --- src/plugins/git/gitclient.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index fe370f45235..dbbb45a16a4 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -3385,8 +3385,14 @@ GitRemote::GitRemote(const QString &url) // Check for local remotes (refer to the root or relative path) // On Windows, local paths typically starts with : + 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('.') - || (HostOsInfo::isWindowsHost() && url[1] == ':')) { + || startsWithWindowsDrive(url)) { protocol = "file"; path = QDir::fromNativeSeparators(url.startsWith("file://") ? url.mid(7) : url); isValid = QDir(path).exists() || QDir(path + ".git").exists();