mirror of git://sourceware.org/git/glibc.git
_nss_compat_initgroups_dyn: Use struct scratch_buffer instead of extend_alloca
This commit is contained in:
parent
866ba63b31
commit
794a74af4d
|
@ -9,6 +9,8 @@
|
||||||
scratch_buffer instead of extend_alloca.
|
scratch_buffer instead of extend_alloca.
|
||||||
* nscd/initgrcache.c: Include <scratch_buffer.h>, now needed by
|
* nscd/initgrcache.c: Include <scratch_buffer.h>, now needed by
|
||||||
grp/compat-initgroups.c.
|
grp/compat-initgroups.c.
|
||||||
|
* nis/nss_compat/compat-initgroups.c (_nss_compat_initgroups_dyn):
|
||||||
|
Rewrite to use struct scratch_buffer instead of extend_alloca.
|
||||||
|
|
||||||
2015-04-08 Joseph Myers <joseph@codesourcery.com>
|
2015-04-08 Joseph Myers <joseph@codesourcery.com>
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
License along with the GNU C Library; if not, see
|
License along with the GNU C Library; if not, see
|
||||||
<http://www.gnu.org/licenses/>. */
|
<http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <alloca.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -30,6 +29,7 @@
|
||||||
#include <nsswitch.h>
|
#include <nsswitch.h>
|
||||||
#include <bits/libc-lock.h>
|
#include <bits/libc-lock.h>
|
||||||
#include <kernel-features.h>
|
#include <kernel-features.h>
|
||||||
|
#include <scratch_buffer.h>
|
||||||
|
|
||||||
static service_user *ni;
|
static service_user *ni;
|
||||||
/* Type of the lookup function. */
|
/* Type of the lookup function. */
|
||||||
|
@ -528,46 +528,31 @@ _nss_compat_initgroups_dyn (const char *user, gid_t group, long int *start,
|
||||||
long int *size, gid_t **groupsp, long int limit,
|
long int *size, gid_t **groupsp, long int limit,
|
||||||
int *errnop)
|
int *errnop)
|
||||||
{
|
{
|
||||||
size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX);
|
|
||||||
char *tmpbuf;
|
|
||||||
enum nss_status status;
|
enum nss_status status;
|
||||||
ent_t intern = { true, false, false, NULL, {NULL, 0, 0} };
|
ent_t intern = { true, false, false, NULL, {NULL, 0, 0} };
|
||||||
bool use_malloc = false;
|
|
||||||
|
|
||||||
status = internal_setgrent (&intern);
|
status = internal_setgrent (&intern);
|
||||||
if (status != NSS_STATUS_SUCCESS)
|
if (status != NSS_STATUS_SUCCESS)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
tmpbuf = __alloca (buflen);
|
struct scratch_buffer tmpbuf;
|
||||||
|
scratch_buffer_init (&tmpbuf);
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
while ((status = internal_getgrent_r (&intern, tmpbuf, buflen,
|
while ((status = internal_getgrent_r (&intern, tmpbuf.data, tmpbuf.length,
|
||||||
user, group, start, size,
|
user, group, start, size,
|
||||||
groupsp, limit, errnop))
|
groupsp, limit, errnop))
|
||||||
== NSS_STATUS_TRYAGAIN && *errnop == ERANGE)
|
== NSS_STATUS_TRYAGAIN && *errnop == ERANGE)
|
||||||
if (__libc_use_alloca (buflen * 2))
|
if (!scratch_buffer_grow (&tmpbuf))
|
||||||
tmpbuf = extend_alloca (tmpbuf, buflen, 2 * buflen);
|
goto done;
|
||||||
else
|
|
||||||
{
|
|
||||||
buflen *= 2;
|
|
||||||
char *newbuf = realloc (use_malloc ? tmpbuf : NULL, buflen);
|
|
||||||
if (newbuf == NULL)
|
|
||||||
{
|
|
||||||
status = NSS_STATUS_TRYAGAIN;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
use_malloc = true;
|
|
||||||
tmpbuf = newbuf;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while (status == NSS_STATUS_SUCCESS);
|
while (status == NSS_STATUS_SUCCESS);
|
||||||
|
|
||||||
status = NSS_STATUS_SUCCESS;
|
status = NSS_STATUS_SUCCESS;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (use_malloc)
|
scratch_buffer_free (&tmpbuf);
|
||||||
free (tmpbuf);
|
|
||||||
|
|
||||||
internal_endgrent (&intern);
|
internal_endgrent (&intern);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue