diff options
author | Ritt Konstantin <ritt.ks@gmail.com> | 2010-04-27 06:12:47 +0400 |
---|---|---|
committer | Qt Commercial Integration <QtCommercial@digia.com> | 2012-01-31 12:24:53 +0200 |
commit | 313c0c388524891c3887a29344135c452c4c301a (patch) | |
tree | 408da3acd7ee8043eacc36dddae19191b9edda0f /tests | |
parent | d56db447348d7b641097bf146d188751ba8a76ae (diff) |
avoid infinite recursion in canonicalized() if cwd is a symlink
if current directory is a symlink to another directory
on the same drive (the simplest example; say, c:\current\dir
is a symlink to c:\target) then the first valid prefix for
"c:\target" in canonicalized() is "c:" (NOT "c:\") and would
be treated like "c:\current\dir" again...and again...
until stack overflow :)
Merge-Request: 494
Task-number: QTBUG-7610
Reviewed-by: Zeno Albisser
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qfileinfo/tst_qfileinfo.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp index 6291f1cf28..af2884809f 100644 --- a/tests/auto/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp @@ -46,6 +46,7 @@ #include <qfile.h> #include <qdir.h> #include <qcoreapplication.h> +#include <qlibrary.h> #include <qtemporaryfile.h> #include <qdir.h> #include <qfileinfo.h> @@ -584,6 +585,25 @@ void tst_QFileInfo::canonicalFilePath() } # endif #endif + +#ifdef Q_OS_WIN + typedef BOOL (WINAPI *PtrCreateSymbolicLink)(LPTSTR, LPTSTR, DWORD); + PtrCreateSymbolicLink ptrCreateSymbolicLink = + (PtrCreateSymbolicLink)QLibrary::resolve(QLatin1String("kernel32"), "CreateSymbolicLink"); + + if (!ptrCreateSymbolicLink || + ptrCreateSymbolicLink((wchar_t*)QString("res").utf16(), (wchar_t*)QString("resources").utf16(), 1) == 0) { + QSKIP("Symbolic links aren't supported by FS", SkipAll); + } + + QString currentPath = QDir::currentPath(); + QCOMPARE(QDir::setCurrent("res"), true); + + QCOMPARE(QFileInfo("file1").canonicalFilePath(), currentPath + "/resources/file1"); + + QCOMPARE(QDir::setCurrent(currentPath), true); + QFile::remove("res"); +#endif } void tst_QFileInfo::fileName_data() |