From 0507fa96513a0542936644415efe4e14010b81c8 Mon Sep 17 00:00:00 2001 From: kh1 Date: Tue, 13 Nov 2012 15:45:37 +0100 Subject: Check for valid drive. Disallow e.g. C:foo\bar Task-number: QTIFW-165 Once we add a something after the colon and before the next slash, the path will be interpreted relative to the current directory, thus leading to unexpected installation directory. Change-Id: I0f32f150707d1b3ca55bd93f230142dad4f7540a Reviewed-by: Tim Jenssen Reviewed-by: Kai Koehne --- src/sdk/installerbasecommons.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/sdk/installerbasecommons.cpp b/src/sdk/installerbasecommons.cpp index 9e8b8ab12..214b6e54b 100644 --- a/src/sdk/installerbasecommons.cpp +++ b/src/sdk/installerbasecommons.cpp @@ -371,15 +371,22 @@ QString TargetDirectoryPageImpl::targetDirWarning() const "absolute path."); } - QString dir = targetDir(); - QString ambiguousChars = QLatin1String("[<>|?*!@#$%^&:,; ]"); - if (packageManagerCore()->settings().allowSpaceInPath()) - ambiguousChars.remove(QLatin1Char(' ')); - + QString dir = QDir::toNativeSeparators(targetDir()); #ifdef Q_OS_WIN + if (dir.count() >= 3 && dir.indexOf(QRegExp(QLatin1String("[a-zA-Z]:"))) == 0 + && dir.at(2) != QLatin1Char('\\')) { + return TargetDirectoryPageImpl::tr("The path you have entered is not valid, please make sure to " + "specify a valid drive."); + } + // remove e.g. "c:" dir = dir.mid(2); #endif + + QString ambiguousChars = QLatin1String("[<>|?*!@#$%^&:,; ]"); + if (packageManagerCore()->settings().allowSpaceInPath()) + ambiguousChars.remove(QLatin1Char(' ')); + // check if there are not allowed characters in the target path if (dir.contains(QRegExp(ambiguousChars))) { return TargetDirectoryPageImpl::tr("The installation path must not contain %1, " -- cgit v1.2.3