From ef53352dbc0a149f6bc6eab555887ac646914144 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Mon, 29 May 2023 21:54:22 +0300 Subject: [PATCH] QFileDialog: use ::sysconf() to get initial passwd struct buffer size Use QVLA since buf is no techincally a var-length-array. Change-Id: I334cf2d1f9ef162495ed223a8e48e1b8e674afc0 Reviewed-by: Thiago Macieira Reviewed-by: Richard Moe Gustavsen --- src/widgets/dialogs/qfiledialog.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 7461a643ad3..6b146bbaa56 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -1109,13 +1109,15 @@ static QString homeDirFromPasswdEntry(const QString &path, const QByteArray &use #if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) && !defined(Q_OS_WASM) passwd pw; passwd *tmpPw; - char buf[200]; - const int bufSize = sizeof(buf); + long bufSize = ::sysconf(_SC_GETPW_R_SIZE_MAX); + if (bufSize == -1) + bufSize = 1024; + QVarLengthArray buf(bufSize); int err = 0; # if defined(Q_OS_SOLARIS) && (_POSIX_C_SOURCE - 0 < 199506L) - tmpPw = getpwnam_r(userName.constData(), &pw, buf, bufSize); + tmpPw = getpwnam_r(userName.constData(), &pw, buf.data(), buf.size()); # else - err = getpwnam_r(userName.constData(), &pw, buf, bufSize, &tmpPw); + err = getpwnam_r(userName.constData(), &pw, buf.data(), buf.size(), &tmpPw); # endif if (err || !tmpPw) return path;