mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
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.
This commit is contained in:
@ -3,6 +3,12 @@
|
|||||||
* elf/pldd.c (main): Rewrite to use struct
|
* elf/pldd.c (main): Rewrite to use struct
|
||||||
scratch_buffer instead of extend_alloca.
|
scratch_buffer instead of extend_alloca.
|
||||||
* elf/pldd-xx.c (find_maps): Likewise.
|
* elf/pldd-xx.c (find_maps): Likewise.
|
||||||
|
* grp/initgroups.c: Include <scratch_buffer.h> instead of
|
||||||
|
<alloca.h>.
|
||||||
|
* grp/compat-initgroups.c (compat_call): Rewrite to use struct
|
||||||
|
scratch_buffer instead of extend_alloca.
|
||||||
|
* nscd/initgrcache.c: Include <scratch_buffer.h>, now needed by
|
||||||
|
grp/compat-initgroups.c.
|
||||||
|
|
||||||
2015-04-08 Joseph Myers <joseph@codesourcery.com>
|
2015-04-08 Joseph Myers <joseph@codesourcery.com>
|
||||||
|
|
||||||
|
@ -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)
|
long int *size, gid_t **groupsp, long int limit, int *errnop)
|
||||||
{
|
{
|
||||||
struct group grpbuf;
|
struct group grpbuf;
|
||||||
size_t buflen = __sysconf (_SC_GETGR_R_SIZE_MAX);
|
|
||||||
enum nss_status status;
|
enum nss_status status;
|
||||||
set_function setgrent_fct;
|
set_function setgrent_fct;
|
||||||
get_function getgrent_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");
|
endgrent_fct = __nss_lookup_function (nip, "endgrent");
|
||||||
|
|
||||||
char *tmpbuf = __alloca (buflen);
|
struct scratch_buffer tmpbuf;
|
||||||
bool use_malloc = false;
|
scratch_buffer_init (&tmpbuf);
|
||||||
enum nss_status result = NSS_STATUS_SUCCESS;
|
enum nss_status result = NSS_STATUS_SUCCESS;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
while ((status = DL_CALL_FCT (getgrent_fct,
|
while ((status = DL_CALL_FCT (getgrent_fct,
|
||||||
(&grpbuf, tmpbuf, buflen, errnop)),
|
(&grpbuf, tmpbuf.data, tmpbuf.length,
|
||||||
|
errnop)),
|
||||||
status == NSS_STATUS_TRYAGAIN)
|
status == NSS_STATUS_TRYAGAIN)
|
||||||
&& *errnop == ERANGE)
|
&& *errnop == ERANGE)
|
||||||
{
|
{
|
||||||
if (__libc_use_alloca (buflen * 2))
|
if (!scratch_buffer_grow (&tmpbuf))
|
||||||
tmpbuf = extend_alloca (tmpbuf, buflen, buflen * 2);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
buflen *= 2;
|
result = NSS_STATUS_TRYAGAIN;
|
||||||
char *newbuf = realloc (use_malloc ? tmpbuf : NULL, buflen);
|
goto done;
|
||||||
if (newbuf == NULL)
|
|
||||||
{
|
|
||||||
result = NSS_STATUS_TRYAGAIN;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
use_malloc = true;
|
|
||||||
tmpbuf = newbuf;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,8 +107,7 @@ compat_call (service_user *nip, const char *user, gid_t group, long int *start,
|
|||||||
while (status == NSS_STATUS_SUCCESS);
|
while (status == NSS_STATUS_SUCCESS);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (use_malloc)
|
scratch_buffer_free (&tmpbuf);
|
||||||
free (tmpbuf);
|
|
||||||
|
|
||||||
if (endgrent_fct)
|
if (endgrent_fct)
|
||||||
DL_CALL_FCT (endgrent_fct, ());
|
DL_CALL_FCT (endgrent_fct, ());
|
||||||
|
@ -15,7 +15,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 <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
@ -26,6 +25,7 @@
|
|||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <nsswitch.h>
|
#include <nsswitch.h>
|
||||||
|
#include <scratch_buffer.h>
|
||||||
|
|
||||||
#include "../nscd/nscd-client.h"
|
#include "../nscd/nscd-client.h"
|
||||||
#include "../nscd/nscd_proto.h"
|
#include "../nscd/nscd_proto.h"
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <scratch_buffer.h>
|
||||||
|
|
||||||
#include "dbg_log.h"
|
#include "dbg_log.h"
|
||||||
#include "nscd.h"
|
#include "nscd.h"
|
||||||
|
Reference in New Issue
Block a user