From 866ba63b312fd015e1585ee46943f57187e82868 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Wed, 8 Apr 2015 20:51:34 +0200 Subject: [PATCH] grp: Rewrite to use struct scratch_buffer instead of extend_alloca grp/compat-initgroups.c is included from nscd/initgrcache.c, which is why the #include directive has to be added there as well. --- ChangeLog | 6 ++++++ grp/compat-initgroups.c | 26 ++++++++------------------ grp/initgroups.c | 2 +- nscd/initgrcache.c | 1 + 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6bd6303f85..3da105b827 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,12 @@ * elf/pldd.c (main): Rewrite to use struct scratch_buffer instead of extend_alloca. * elf/pldd-xx.c (find_maps): Likewise. + * grp/initgroups.c: Include instead of + . + * grp/compat-initgroups.c (compat_call): Rewrite to use struct + scratch_buffer instead of extend_alloca. + * nscd/initgrcache.c: Include , now needed by + grp/compat-initgroups.c. 2015-04-08 Joseph Myers diff --git a/grp/compat-initgroups.c b/grp/compat-initgroups.c index ff10e247f4..3dd50d2306 100644 --- a/grp/compat-initgroups.c +++ b/grp/compat-initgroups.c @@ -14,7 +14,6 @@ compat_call (service_user *nip, const char *user, gid_t group, long int *start, long int *size, gid_t **groupsp, long int limit, int *errnop) { struct group grpbuf; - size_t buflen = __sysconf (_SC_GETGR_R_SIZE_MAX); enum nss_status status; set_function setgrent_fct; get_function getgrent_fct; @@ -35,30 +34,22 @@ compat_call (service_user *nip, const char *user, gid_t group, long int *start, endgrent_fct = __nss_lookup_function (nip, "endgrent"); - char *tmpbuf = __alloca (buflen); - bool use_malloc = false; + struct scratch_buffer tmpbuf; + scratch_buffer_init (&tmpbuf); enum nss_status result = NSS_STATUS_SUCCESS; do { while ((status = DL_CALL_FCT (getgrent_fct, - (&grpbuf, tmpbuf, buflen, errnop)), + (&grpbuf, tmpbuf.data, tmpbuf.length, + errnop)), status == NSS_STATUS_TRYAGAIN) && *errnop == ERANGE) { - if (__libc_use_alloca (buflen * 2)) - tmpbuf = extend_alloca (tmpbuf, buflen, buflen * 2); - else + if (!scratch_buffer_grow (&tmpbuf)) { - buflen *= 2; - char *newbuf = realloc (use_malloc ? tmpbuf : NULL, buflen); - if (newbuf == NULL) - { - result = NSS_STATUS_TRYAGAIN; - goto done; - } - use_malloc = true; - tmpbuf = newbuf; + result = NSS_STATUS_TRYAGAIN; + goto done; } } @@ -116,8 +107,7 @@ compat_call (service_user *nip, const char *user, gid_t group, long int *start, while (status == NSS_STATUS_SUCCESS); done: - if (use_malloc) - free (tmpbuf); + scratch_buffer_free (&tmpbuf); if (endgrent_fct) DL_CALL_FCT (endgrent_fct, ()); diff --git a/grp/initgroups.c b/grp/initgroups.c index 4d083acee5..14a8ab158d 100644 --- a/grp/initgroups.c +++ b/grp/initgroups.c @@ -15,7 +15,6 @@ License along with the GNU C Library; if not, see . */ -#include #include #include #include @@ -26,6 +25,7 @@ #include #include #include +#include #include "../nscd/nscd-client.h" #include "../nscd/nscd_proto.h" diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c index 7ba76be7c7..e45d65c006 100644 --- a/nscd/initgrcache.c +++ b/nscd/initgrcache.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "dbg_log.h" #include "nscd.h"