summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2011-02-06 17:58:00 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2011-02-08 11:54:35 (GMT)
commit609bcb4f9ab3f8fecd037e9c401891ca4d6f2172 (patch)
treebbf013c20ed6a01ea18dd897a74222054672f099 /src
parent8d6ad569495d389b111ab8879117cc7832287fa8 (diff)
downloadQt-609bcb4f9ab3f8fecd037e9c401891ca4d6f2172.zip
Qt-609bcb4f9ab3f8fecd037e9c401891ca4d6f2172.tar.gz
Qt-609bcb4f9ab3f8fecd037e9c401891ca4d6f2172.tar.bz2
Use an increasing size for the getpwuid_r buffer.
Reviewed-by: Bradley T. Hughes
Diffstat (limited to 'src')
-rw-r--r--src/gui/kernel/qapplication_x11.cpp13
1 files changed, 12 insertions, 1 deletions
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<char, 1024> buf(qMax<long>(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