summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qtemporaryfile.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2020-04-08 15:36:01 -0300
committerThiago Macieira <thiago.macieira@intel.com>2020-04-08 19:55:00 -0300
commit36feab8bf49b4c57a45b6668921e8accaa167c36 (patch)
treefdad84799c3d1ea9fe5e4adc5bcd4d5760f7cd2b /src/corelib/io/qtemporaryfile.cpp
parentfa463fa721b2f15cc8b95334306f1377a7e9e100 (diff)
QTemporaryFile/Linux: don't cut the root dir's slash
Normally people shouldn't create temporary files on /, but if you're running as root, why not? Caught when running tst_qtemporaryfile as root: openat(AT_FDCWD, "", O_RDWR|O_CLOEXEC|O_TMPFILE, 0600) = -1 ENOENT (No such file or directory) Change-Id: Ibdc95e9af7bd456a94ecfffd1603ebfc17cea220 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/corelib/io/qtemporaryfile.cpp')
-rw-r--r--src/corelib/io/qtemporaryfile.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index 55d13dad70..c016a622c7 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -284,8 +284,10 @@ createUnnamedFile(NativeFileHandle &file, QTemporaryFileName &tfn, quint32 mode,
return CreateUnnamedFileStatus::NotSupported;
const char *p = ".";
- int lastSlash = tfn.path.lastIndexOf('/');
- if (lastSlash != -1) {
+ QByteArray::size_type lastSlash = tfn.path.lastIndexOf('/');
+ if (lastSlash >= 0) {
+ if (lastSlash == 0)
+ lastSlash = 1;
tfn.path[lastSlash] = '\0';
p = tfn.path.data();
}