diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2017-07-12 18:41:35 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2017-08-09 05:19:23 +0000 |
commit | 9312ec54dbf8031f4d23c6fc400c1ca27e3f9d1f (patch) | |
tree | 09e4443fd5b5762ab1499404d9598c13fe7fc465 /src/corelib/io/qfsfileengine_unix.cpp | |
parent | 284fff12172095a899303d9b4fc06c7bf502c93d (diff) |
Fix QAbstractFileEngine::clone misuse
QFile::copy was assuming that the target file was native and therefore
it could simply take the file descriptor to clone. While that was not
currently a problem, in theory it could be as we do have one writeable
file engine besides QFSFileEngine (QWinRTFileEngine).
By refactoring to take the parameter as a QAbstractFileEngine, we can
ensure that the target file is a native file.
Change-Id: Ib7a1737987bf4c4a8c51fffd14d0c048fd509025
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/io/qfsfileengine_unix.cpp')
-rw-r--r-- | src/corelib/io/qfsfileengine_unix.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index bb9b3dc87a..83091ca808 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -735,16 +735,19 @@ bool QFSFileEnginePrivate::unmap(uchar *ptr) /*! \reimp */ -bool QFSFileEngine::clone(int sourceHandle) +bool QFSFileEngine::cloneTo(QAbstractFileEngine *target) { + if ((target->fileFlags(LocalDiskFlag) & LocalDiskFlag) == 0) + return false; #if defined(Q_OS_LINUX) Q_D(QFSFileEngine); # if !defined FICLONE # define FICLONE _IOW (0x94, 9, int) # endif - return ::ioctl(d->fd, FICLONE, sourceHandle) == 0; + int srcfd = d->nativeHandle(); + int dstfd = target->handle(); + return ::ioctl(dstfd, FICLONE, srcfd) == 0; #else - Q_UNUSED(sourceHandle); return false; #endif } |