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>
This commit is contained in:
Thomas McGuire 2012-09-10 09:54:14 +02:00 committed by Qt by Nokia
parent e9c9e8bfa9
commit ad5d64226a

View File

@ -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) {