From 198ce19e46c610db3d4f1e08699ca2049c90b12e Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 25 Sep 2022 11:43:15 +0200 Subject: [PATCH] App: Consider using getpwuid_r(...) instead of getpwuid(...) for improved thread safety. [runtime/threadsafe_fn] --- src/App/Application.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 229e30b036..9be316acd7 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -2912,10 +2912,15 @@ QString getUserHome() QString path; #if defined(FC_OS_LINUX) || defined(FC_OS_CYGWIN) || defined(FC_OS_BSD) || defined(FC_OS_MACOSX) // Default paths for the user specific stuff - struct passwd *pwd = getpwuid(getuid()); - if (!pwd) + struct passwd pwd; + struct passwd *result; + const std::size_t buflen = 16384; + std::vector buffer(buflen); + int error = getpwuid_r(getuid(), &pwd, buffer.data(), buffer.size(), &result); + Q_UNUSED(error) + if (!result) throw Base::RuntimeError("Getting HOME path from system failed!"); - path = QString::fromUtf8(pwd->pw_dir); + path = QString::fromUtf8(result->pw_dir); #else path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); #endif