From 36feab8bf49b4c57a45b6668921e8accaa167c36 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 8 Apr 2020 15:36:01 -0300 Subject: 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 Reviewed-by: David Faure --- src/corelib/io/qtemporaryfile.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') 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(); } -- cgit v1.2.3