summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2011-09-01 14:04:33 (GMT)
committerShane Kearns <shane.kearns@accenture.com>2011-09-02 12:38:57 (GMT)
commitddf5a09d469a1ded5490cffe54e0013a0d5ba347 (patch)
tree656e7a7abaacd551f554bf2326dba20276eb194d /src/corelib
parentca34cc75294e0d2a8bc491a2c679fe8a69cd0408 (diff)
downloadQt-ddf5a09d469a1ded5490cffe54e0013a0d5ba347.zip
Qt-ddf5a09d469a1ded5490cffe54e0013a0d5ba347.tar.gz
Qt-ddf5a09d469a1ded5490cffe54e0013a0d5ba347.tar.bz2
Fix comparison of absolute, unclean paths in QDir
QDir::operator== was creating a clean absolute path for comparison purposes if the original path was relative. However original absolute paths were trusted, even though they could be unclean. Now they are checked for cleanliness first. Task-Number: QTBUG-19995 Task-Number: QTBUG-20495 Change-Id: I047a1a40ae5151e4604085e4ac87f30a4e4979c4 Reviewed-on: http://codereview.qt.nokia.com/4099 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Prasanth Ullattil <prasanth.ullattil@nokia.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/io/qdir.cpp2
-rw-r--r--src/corelib/io/qfilesystementry.cpp31
-rw-r--r--src/corelib/io/qfilesystementry_p.h1
3 files changed, 33 insertions, 1 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index c0c62e1..3271148 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -198,7 +198,7 @@ inline void QDirPrivate::resolveAbsoluteEntry() const
QString absoluteName;
if (fileEngine.isNull()) {
- if (!dirEntry.isRelative()) {
+ if (!dirEntry.isRelative() && dirEntry.isClean()) {
absoluteDirEntry = dirEntry;
return;
}
diff --git a/src/corelib/io/qfilesystementry.cpp b/src/corelib/io/qfilesystementry.cpp
index bb7cb4e..2f37542 100644
--- a/src/corelib/io/qfilesystementry.cpp
+++ b/src/corelib/io/qfilesystementry.cpp
@@ -380,4 +380,35 @@ void QFileSystemEntry::findFileNameSeparators() const
}
}
+bool QFileSystemEntry::isClean() const
+{
+ resolveFilePath();
+ int dots = 0;
+ bool dotok = true; // checking for ".." or "." starts to relative paths
+ bool slashok = true;
+ for (QString::const_iterator iter = m_filePath.constBegin(); iter != m_filePath.constEnd(); iter++) {
+ if (*iter == QLatin1Char('/')) {
+ if (dots == 1 || dots == 2)
+ return false; // path contains "./" or "../"
+ if (!slashok)
+ return false; // path contains "//"
+ dots = 0;
+ dotok = true;
+ slashok = false;
+ } else if (dotok) {
+ slashok = true;
+ if (*iter == QLatin1Char('.')) {
+ dots++;
+ if (dots > 2)
+ dotok = false;
+ } else {
+ //path element contains a character other than '.', it's clean
+ dots = 0;
+ dotok = false;
+ }
+ }
+ }
+ return (dots != 1 && dots != 2); // clean if path doesn't end in . or ..
+}
+
QT_END_NAMESPACE
diff --git a/src/corelib/io/qfilesystementry_p.h b/src/corelib/io/qfilesystementry_p.h
index 34b083a..8d524c0 100644
--- a/src/corelib/io/qfilesystementry_p.h
+++ b/src/corelib/io/qfilesystementry_p.h
@@ -91,6 +91,7 @@ public:
QString completeSuffix() const;
bool isAbsolute() const;
bool isRelative() const;
+ bool isClean() const;
#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
bool isDriveRoot() const;