From 23d08ce2edab09562ad283dac5d46c09efec63ca Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 16 Feb 2017 13:58:55 -0800 Subject: Fix QDir::mkpath() when the path contains "symlink/../" It is incorrect to collapse a "symlink/.." segment because the parent directory of the symlink's target may not be the directory where the symlink itself is located. [ChangeLog][QtCore][QDir] Fixed a bug that caused QDir::mkpath() to create the wrong directory if the requested path contained a symbolic link and "../". Change-Id: Iaddbecfbba5441c8b2e4fffd14a3e367730a1e24 Reviewed-by: Oswald Buddenhagen Reviewed-by: David Faure --- src/corelib/io/qfilesystemengine_unix.cpp | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 3cb412e47c..e195afdae9 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2017 Intel Corporation. ** Copyright (C) 2016 The Qt Company Ltd. ** Copyright (C) 2013 Samuel Gaist ** Contact: https://www.qt.io/licensing/ @@ -603,25 +604,7 @@ bool QFileSystemEngine::createDirectory(const QFileSystemEntry &entry, bool crea if (!createParents) return false; - // we need the cleaned path in order to create the parents - // and we save errno just in case encodeName needs to load codecs - int savedErrno = errno; - bool pathChanged; - { - QString cleanName = QDir::cleanPath(dirName); - - // Check if the cleaned name is the same or not. If we were given a - // path with resolvable "../" sections, cleanPath will remove them, but - // this may change the target dir if one of those segments was a - // symlink. This operation depends on cleanPath's optimization of - // returning the original string if it didn't modify anything. - pathChanged = !dirName.isSharedWith(cleanName); - if (pathChanged) - nativeName = QFile::encodeName(cleanName); - } - - errno = savedErrno; - return createDirectoryWithParents(nativeName, pathChanged); + return createDirectoryWithParents(nativeName, false); } //static -- cgit v1.2.3