summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2011-08-05 10:45:08 +0200
committerQt by Nokia <qt-info@nokia.com>2011-10-21 22:20:18 +0200
commitf4f729cb7bccd8bc4812dd15855dfc5af4ff6c8c (patch)
tree681f214f3429836cca66905bdb58e4949e953f45 /tests
parenta4a09488ee979849f4e9b9b3b8590ad2a2472590 (diff)
Atomic implementation of create file and obtain handle for Win/Symbian
Besides generating a unique name, createFileFromTemplate now also acquires a file handle on all platforms. The file engine's native handle is passed by reference and modified in place. This fixes a long standing security issue on Windows. On Windows and Symbian platforms we directly use the "native" file path when processing the template and generating the unique name. Since the native encoding is known, conversions at this point are safe. Errors other than "file exists" are propagated to Q(Temporary)File, and result in a failure in open(). The changes also unify error handling and should give consistent behaviour across all platforms. Worthy of note, there's a change in behaviour on Windows and Symbian: fileNames returned by QTemporaryFile on Windows and Symbian are always absolute after open has been called. This has to do with how QFileSystemEntry::nativeFilePath works on these platforms. (Test was updated to reflect change in behaviour.) Reviewed-by: Gareth Stockwell Reviewed-by: Shane Kearns (cherry picked from commit ff9b69838ec146aeb43d4af8a03043f9c5f0454d) Conflicts: tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp Change-Id: Ibc9affb321ea4f4b193efc1f7336c9770b43d8df Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp31
1 files changed, 20 insertions, 11 deletions
diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
index 916393eee7..655c167c21 100644
--- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -199,11 +199,12 @@ void tst_QTemporaryFile::fileTemplate()
QCOMPARE(file.open(), true);
+ QString fileName = QFileInfo(file).fileName();
if (prefix.length())
- QCOMPARE(file.fileName().left(prefix.length()), prefix);
+ QCOMPARE(fileName.left(prefix.length()), prefix);
if (suffix.length())
- QCOMPARE(file.fileName().right(suffix.length()), suffix);
+ QCOMPARE(fileName.right(suffix.length()), suffix);
}
@@ -716,20 +717,28 @@ void tst_QTemporaryFile::QTBUG_4796()
<< file5.fileName()
<< file6.fileName();
- QVERIFY(file1.fileName().startsWith(fileTemplate1 + QLatin1Char('.')));
- QVERIFY(file2.fileName().startsWith(fileTemplate2 + QLatin1Char('.')));
- QVERIFY(file5.fileName().startsWith("test-XXXXXX/" + fileTemplate1 + QLatin1Char('.')));
- QVERIFY(file6.fileName().startsWith("test-XXXXXX/" + prefix));
+ QDir currentDir;
+ QString fileName1 = currentDir.relativeFilePath(file1.fileName());
+ QString fileName2 = currentDir.relativeFilePath(file2.fileName());
+ QString fileName3 = currentDir.relativeFilePath(file3.fileName());
+ QString fileName4 = currentDir.relativeFilePath(file4.fileName());
+ QString fileName5 = currentDir.relativeFilePath(file5.fileName());
+ QString fileName6 = currentDir.relativeFilePath(file6.fileName());
+
+ QVERIFY(fileName1.startsWith(fileTemplate1 + QLatin1Char('.')));
+ QVERIFY(fileName2.startsWith(fileTemplate2 + QLatin1Char('.')));
+ QVERIFY(fileName5.startsWith("test-XXXXXX/" + fileTemplate1 + QLatin1Char('.')));
+ QVERIFY(fileName6.startsWith("test-XXXXXX/" + prefix));
if (!prefix.isEmpty()) {
- QVERIFY(file3.fileName().startsWith(prefix));
- QVERIFY(file4.fileName().startsWith(prefix));
+ QVERIFY(fileName3.startsWith(prefix));
+ QVERIFY(fileName4.startsWith(prefix));
}
if (!suffix.isEmpty()) {
- QVERIFY(file3.fileName().endsWith(suffix));
- QVERIFY(file4.fileName().endsWith(suffix));
- QVERIFY(file6.fileName().endsWith(suffix));
+ QVERIFY(fileName3.endsWith(suffix));
+ QVERIFY(fileName4.endsWith(suffix));
+ QVERIFY(fileName6.endsWith(suffix));
}
}
}