summaryrefslogtreecommitdiff
path: root/debian/patches/00_0167-fix-group-reading.dpatch
blob: d7f8a07672e8a92fa9f37c0876ac412dd0840432 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! /bin/sh /usr/share/dpatch/dpatch-run
## 00_0167-fix-group-reading.dpatch by Dirk Mueller <mueller@kde.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: In big user environments, getgrgid_r() needs more memory than sysconf() returns.

@DPATCH@
diff -urNad qt4-x11-4.3.0~/src/corelib/io/qfsfileengine_unix.cpp qt4-x11-4.3.0/src/corelib/io/qfsfileengine_unix.cpp
--- qt4-x11-4.3.0~/src/corelib/io/qfsfileengine_unix.cpp	2007-05-25 15:24:09.000000000 +0200
+++ qt4-x11-4.3.0/src/corelib/io/qfsfileengine_unix.cpp	2007-06-26 19:56:03.000000000 +0200
@@ -830,9 +830,16 @@
     } else if (own == OwnerGroup) {
         struct group *gr = 0;
 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD)
-        buf.resize(sysconf(_SC_GETGR_R_SIZE_MAX));
-        struct group entry;
-        getgrgid_r(ownerId(own), &entry, buf.data(), buf.size(), &gr);
+        for (unsigned size = sysconf(_SC_GETGR_R_SIZE_MAX); size < 256000; size += size)
+        {
+            buf.resize(size);
+            struct group entry;
+            // ERANGE indicates that the buffer was too small
+            if (!getgrgid_r(ownerId(own), &entry, buf.data(), buf.size(), &gr)
+                || errno != ERANGE)
+                break;
+        }
+
 #else
         gr = getgrgid(ownerId(own));
 #endif