1 diff -pruN glibc-2.12-2-gc4ccff1/nis/nss_compat/compat-initgroups.c glibc-2.12-2-gc4ccff1.patched/nis/nss_compat/compat-initgroups.c
2 --- glibc-2.12-2-gc4ccff1/nis/nss_compat/compat-initgroups.c 2010-05-04 16:57:23.000000000 +0530
3 +++ glibc-2.12-2-gc4ccff1.patched/nis/nss_compat/compat-initgroups.c 2012-02-21 11:11:19.877008465 +0530
4 @@ -297,6 +297,8 @@ getgrent_next_nss (ent_t *ent, char *buf
5 if (nss_initgroups_dyn (user, group, &mystart, &mysize, &mygroups,
6 limit, errnop) == NSS_STATUS_SUCCESS)
8 + status = NSS_STATUS_NOTFOUND;
10 /* If there is no blacklist we can trust the underlying
11 initgroups implementation. */
12 if (ent->blacklist.current <= 1)
13 @@ -309,6 +311,7 @@ getgrent_next_nss (ent_t *ent, char *buf
14 overwrite the pointer with one to a bigger buffer. */
15 char *tmpbuf = buffer;
16 size_t tmplen = buflen;
17 + bool use_malloc = false;
19 for (int i = 0; i < mystart; i++)
21 @@ -316,21 +319,36 @@ getgrent_next_nss (ent_t *ent, char *buf
22 tmpbuf, tmplen, errnop))
23 == NSS_STATUS_TRYAGAIN
25 - if (tmpbuf == buffer)
28 - tmpbuf = __alloca (tmplen);
31 - tmpbuf = extend_alloca (tmpbuf, tmplen, 2 * tmplen);
33 + if (__libc_use_alloca (tmplen * 2))
35 + if (tmpbuf == buffer)
38 + tmpbuf = __alloca (tmplen);
41 + tmpbuf = extend_alloca (tmpbuf, tmplen, tmplen * 2);
46 + char *newbuf = realloc (use_malloc ? tmpbuf : NULL, tmplen);
50 + status = NSS_STATUS_TRYAGAIN;
58 if (__builtin_expect (status != NSS_STATUS_NOTFOUND, 1))
60 if (__builtin_expect (status != NSS_STATUS_SUCCESS, 0))
67 if (!in_blacklist (grpbuf.gr_name,
68 strlen (grpbuf.gr_name), ent)
69 @@ -348,11 +366,17 @@ getgrent_next_nss (ent_t *ent, char *buf
74 + status = NSS_STATUS_NOTFOUND;
83 - return NSS_STATUS_NOTFOUND;
88 @@ -506,6 +530,7 @@ _nss_compat_initgroups_dyn (const char *
90 enum nss_status status;
91 ent_t intern = { true, false, false, NULL, {NULL, 0, 0} };
92 + bool use_malloc = false;
94 status = internal_setgrent (&intern);
95 if (status != NSS_STATUS_SUCCESS)
96 @@ -519,13 +544,32 @@ _nss_compat_initgroups_dyn (const char *
97 user, group, start, size,
98 groupsp, limit, errnop))
99 == NSS_STATUS_TRYAGAIN && *errnop == ERANGE)
100 - tmpbuf = extend_alloca (tmpbuf, buflen, 2 * buflen);
101 + if (__libc_use_alloca (buflen * 2))
102 + tmpbuf = extend_alloca (tmpbuf, buflen, 2 * buflen);
106 + char *newbuf = realloc (use_malloc ? tmpbuf : NULL, buflen);
107 + if (newbuf == NULL)
109 + status = NSS_STATUS_TRYAGAIN;
116 while (status == NSS_STATUS_SUCCESS);
118 + status = NSS_STATUS_SUCCESS;
124 internal_endgrent (&intern);
126 - return NSS_STATUS_SUCCESS;