diff options
author | Thomas McGuire <thomas.mcguire.qnx@kdab.com> | 2012-09-10 09:54:14 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-09-10 14:09:45 +0200 |
commit | ad5d64226abd50a43856ab560583f37b49ff04c9 (patch) | |
tree | 9a624ba5e44ee8bd03802b04d37dea3559ed107a /src/corelib/io/qfilesystemengine_unix.cpp | |
parent | e9c9e8bfa93b467a06a6cd872712845cacc465c8 (diff) |
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 <giuseppe.dangelo@kdab.com>
Reviewed-by: Qt Doc Bot <qt_docbot@qt-project.org>
Diffstat (limited to 'src/corelib/io/qfilesystemengine_unix.cpp')
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 9 |
1 files 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) { |