diff options
author | Jonas Gastal <jgastal@profusion.mobi> | 2012-01-29 22:57:56 -0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-07 22:05:51 +0100 |
commit | 63f634322b2c0f795bd424be9e51953a10c701de (patch) | |
tree | 63c1cad957bc1a319a27986052ec6a535ed422cc /src/corelib/io | |
parent | 763d0a55e912689f2c0cbad41e81cdc3dbf402d0 (diff) |
Don't allow cd'ing to above root.
Task-number: QTBUG-23893
Change-Id: Ifc6e22f135a1f6bff7c0fa8bef3ea7e1042ae819
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qdir.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index afd6620e65..220fc43b92 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -861,19 +861,28 @@ bool QDir::cd(const QString &dirName) if (isAbsolutePath(dirName)) { newPath = cleanPath(dirName); } else { - if (isRoot()) { - if (dirName == QLatin1String("..")) - return false; + if (isRoot()) newPath = d->dirEntry.filePath(); - } else { + else newPath = d->dirEntry.filePath() % QLatin1Char('/'); - } - newPath += dirName; if (dirName.indexOf(QLatin1Char('/')) >= 0 || dirName == QLatin1String("..") || d->dirEntry.filePath() == QLatin1String(".")) { newPath = cleanPath(newPath); +#if defined (Q_OS_UNIX) + //After cleanPath() if path is "/.." or starts with "/../" it means trying to cd above root. + if (newPath.startsWith(QLatin1String("/../")) || newPath == QLatin1String("/..")) +#else + /* + cleanPath() already took care of replacing '\' with '/'. + We can't use startsWith here because the letter of the drive is unknown. + After cleanPath() if path is "[A-Z]:/.." or starts with "[A-Z]:/../" it means trying to cd above root. + */ + + if (newPath.midRef(1, 4) == QLatin1String(":/..") && (newPath.length() == 5 || newPath.at(5) == QLatin1Char('/'))) +#endif + return false; /* If newPath starts with .., we convert it to absolute to avoid infinite looping on |