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>
}
}
# 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) {