From 609bcb4f9ab3f8fecd037e9c401891ca4d6f2172 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 6 Feb 2011 18:58:00 +0100 Subject: Use an increasing size for the getpwuid_r buffer. Reviewed-by: Bradley T. Hughes --- src/gui/kernel/qapplication_x11.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp index 8fef6fb..4cdb82f 100644 --- a/src/gui/kernel/qapplication_x11.cpp +++ b/src/gui/kernel/qapplication_x11.cpp @@ -5659,7 +5659,18 @@ static void sm_performSaveYourself(QSessionManagerPrivate* smd) #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) QVarLengthArray buf(qMax(sysconf(_SC_GETPW_R_SIZE_MAX), 1024L)); struct passwd entry; - getpwuid_r(geteuid(), &entry, buf.data(), buf.size(), &entryPtr); + while (getpwuid_r(geteuid(), &entry, buf.data(), buf.size(), &entryPtr) == ERANGE) { + if (buf.size() >= 32768) { + // too big already, fail + static char badusername[] = ""; + entryPtr = &entry; + entry.pw_name = badusername; + break; + } + + // retry with a bigger buffer + buf.resize(buf.size() * 2); + } #else entryPtr = getpwuid(geteuid()); #endif -- cgit v0.12