From ad5d64226abd50a43856ab560583f37b49ff04c9 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Mon, 10 Sep 2012 09:54:14 +0200 Subject: [PATCH] Fix QFileSystemEngine::canonicalName() returning corrupt data In case of an error when calling realpath(), the return value buffer was uninitalized, but still used. Now the error value is checked to prevent this. Additionally, this fixes a memory leak in the error case. In addition, use the modern version of realpath() on QNX, since it is available there. Change-Id: I0ac83454679619f379df9c482c958789ab31866a Reviewed-by: Giuseppe D'Angelo Reviewed-by: Qt Doc Bot --- src/corelib/io/qfilesystemengine_unix.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 21e2987782..9e2c69f088 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -191,11 +191,16 @@ QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry, } } # else -# if _POSIX_VERSION >= 200801L +# if (_POSIX_VERSION >= 200801L || defined(Q_OS_QNX)) ret = realpath(entry.nativeFilePath().constData(), (char*)0); # else ret = (char*)malloc(PATH_MAX); - realpath(entry.nativeFilePath().constData(), (char*)ret); + if (realpath(entry.nativeFilePath().constData(), (char*)ret) == 0) { + const int savedErrno = errno; // errno is checked below, and free() might change it + free(ret); + errno = savedErrno; + ret = 0; + } # endif # endif if (ret) {