mirror of git://sourceware.org/git/glibc.git
Update.
2002-03-21 Ulrich Drepper <drepper@redhat.com> * nscd/grpcache.c (addgrbyname): Improve buffer allocate with alloca. Use realloc if too large. (addgrbyid): Likewise. * nscd/hstcache.c (addhstbyname): Likewise. (addhstbyaddr): Likewise. (addhstbynamev6): Likewise. (addhstbyaddrv6): Likewise. * nscd/pwdcache.c (addpwbyname): Likewise. (addpwbyuid): Likewise.
This commit is contained in:
parent
0472723ab8
commit
c7a9b6e2d3
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
||||||
|
2002-03-21 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* nscd/grpcache.c (addgrbyname): Improve buffer allocate with alloca.
|
||||||
|
Use realloc if too large.
|
||||||
|
(addgrbyid): Likewise.
|
||||||
|
* nscd/hstcache.c (addhstbyname): Likewise.
|
||||||
|
(addhstbyaddr): Likewise.
|
||||||
|
(addhstbynamev6): Likewise.
|
||||||
|
(addhstbyaddrv6): Likewise.
|
||||||
|
* nscd/pwdcache.c (addpwbyname): Likewise.
|
||||||
|
(addpwbyuid): Likewise.
|
||||||
|
|
||||||
2002-03-21 Andreas Jaeger <aj@suse.de>
|
2002-03-21 Andreas Jaeger <aj@suse.de>
|
||||||
|
|
||||||
* sysdeps/unix/sysv/linux/x86_64/bits/sigcontext.h (struct
|
* sysdeps/unix/sysv/linux/x86_64/bits/sigcontext.h (struct
|
||||||
|
|
|
@ -207,13 +207,13 @@ addgrbyname (struct database *db, int fd, request_header *req,
|
||||||
simply insert it. It does not matter if it is in there twice. The
|
simply insert it. It does not matter if it is in there twice. The
|
||||||
pruning function only will look at the timestamp. */
|
pruning function only will look at the timestamp. */
|
||||||
int buflen = 1024;
|
int buflen = 1024;
|
||||||
char *buffer = alloca (buflen);
|
char *buffer = (char *) alloca (buflen);
|
||||||
struct group resultbuf;
|
struct group resultbuf;
|
||||||
struct group *grp;
|
struct group *grp;
|
||||||
uid_t oldeuid = 0;
|
uid_t oldeuid = 0;
|
||||||
bool use_malloc = false;
|
bool use_malloc = false;
|
||||||
|
|
||||||
if (debug_level > 0)
|
if (__builtin_expect (debug_level > 0, 0))
|
||||||
dbg_log (_("Haven't found \"%s\" in group cache!"), (char *) key);
|
dbg_log (_("Haven't found \"%s\" in group cache!"), (char *) key);
|
||||||
|
|
||||||
if (secure[grpdb])
|
if (secure[grpdb])
|
||||||
|
@ -245,7 +245,7 @@ addgrbyname (struct database *db, int fd, request_header *req,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
buffer = alloca (buflen);
|
buffer = (char *) alloca (buflen);
|
||||||
#if _STACK_GROWS_DOWN
|
#if _STACK_GROWS_DOWN
|
||||||
if (buffer + buflen == old_buffer)
|
if (buffer + buflen == old_buffer)
|
||||||
buflen = 2 * buflen - 1024;
|
buflen = 2 * buflen - 1024;
|
||||||
|
@ -278,7 +278,7 @@ addgrbygid (struct database *db, int fd, request_header *req,
|
||||||
simply insert it. It does not matter if it is in there twice. The
|
simply insert it. It does not matter if it is in there twice. The
|
||||||
pruning function only will look at the timestamp. */
|
pruning function only will look at the timestamp. */
|
||||||
int buflen = 1024;
|
int buflen = 1024;
|
||||||
char *buffer = alloca (buflen);
|
char *buffer = (char *) alloca (buflen);
|
||||||
struct group resultbuf;
|
struct group resultbuf;
|
||||||
struct group *grp;
|
struct group *grp;
|
||||||
uid_t oldeuid = 0;
|
uid_t oldeuid = 0;
|
||||||
|
@ -295,7 +295,7 @@ addgrbygid (struct database *db, int fd, request_header *req,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug_level > 0)
|
if (__builtin_expect (debug_level > 0, 0))
|
||||||
dbg_log (_("Haven't found \"%d\" in group cache!"), gid);
|
dbg_log (_("Haven't found \"%d\" in group cache!"), gid);
|
||||||
|
|
||||||
if (secure[grpdb])
|
if (secure[grpdb])
|
||||||
|
@ -327,7 +327,7 @@ addgrbygid (struct database *db, int fd, request_header *req,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
buffer = alloca (buflen);
|
buffer = (char *) alloca (buflen);
|
||||||
#if _STACK_GROWS_DOWN
|
#if _STACK_GROWS_DOWN
|
||||||
if (buffer + buflen == old_buffer)
|
if (buffer + buflen == old_buffer)
|
||||||
buflen = 2 * buflen - 1024;
|
buflen = 2 * buflen - 1024;
|
||||||
|
|
176
nscd/hstcache.c
176
nscd/hstcache.c
|
@ -1,5 +1,5 @@
|
||||||
/* Cache handling for host lookup.
|
/* Cache handling for host lookup.
|
||||||
Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
|
Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
|
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <error.h>
|
#include <error.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -31,6 +32,7 @@
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <arpa/nameser.h>
|
#include <arpa/nameser.h>
|
||||||
|
#include <stackinfo.h>
|
||||||
|
|
||||||
#include "nscd.h"
|
#include "nscd.h"
|
||||||
#include "dbg_log.h"
|
#include "dbg_log.h"
|
||||||
|
@ -289,13 +291,14 @@ addhstbyname (struct database *db, int fd, request_header *req,
|
||||||
look again in the table whether the dataset is now available. We
|
look again in the table whether the dataset is now available. We
|
||||||
simply insert it. It does not matter if it is in there twice. The
|
simply insert it. It does not matter if it is in there twice. The
|
||||||
pruning function only will look at the timestamp. */
|
pruning function only will look at the timestamp. */
|
||||||
int buflen = 512;
|
int buflen = 1024;
|
||||||
char *buffer = alloca (buflen);
|
char *buffer = (char *) alloca (buflen);
|
||||||
struct hostent resultbuf;
|
struct hostent resultbuf;
|
||||||
struct hostent *hst;
|
struct hostent *hst;
|
||||||
uid_t oldeuid = 0;
|
uid_t oldeuid = 0;
|
||||||
|
bool use_malloc = false;
|
||||||
|
|
||||||
if (debug_level > 0)
|
if (__builtin_expect (debug_level > 0, 0))
|
||||||
dbg_log (_("Haven't found \"%s\" in hosts cache!"), (char *) key);
|
dbg_log (_("Haven't found \"%s\" in hosts cache!"), (char *) key);
|
||||||
|
|
||||||
if (secure[hstdb])
|
if (secure[hstdb])
|
||||||
|
@ -309,15 +312,47 @@ addhstbyname (struct database *db, int fd, request_header *req,
|
||||||
&& h_errno == NETDB_INTERNAL
|
&& h_errno == NETDB_INTERNAL
|
||||||
&& errno == ERANGE)
|
&& errno == ERANGE)
|
||||||
{
|
{
|
||||||
|
char *old_buffer = buffer;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
buflen += 256;
|
buflen += 1024;
|
||||||
buffer = alloca (buflen);
|
|
||||||
|
if (__builtin_expect (buflen > 32768, 0))
|
||||||
|
{
|
||||||
|
buffer = (char *) realloc (use_malloc ? buffer : NULL, buflen);
|
||||||
|
if (buffer == NULL)
|
||||||
|
{
|
||||||
|
/* We ran out of memory. We cannot do anything but
|
||||||
|
sending a negative response. In reality this should
|
||||||
|
never happen. */
|
||||||
|
hst = NULL;
|
||||||
|
buffer = old_buffer;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
use_malloc = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer = (char *) alloca (buflen);
|
||||||
|
#if _STACK_GROWS_DOWN
|
||||||
|
if (buffer + buflen == old_buffer)
|
||||||
|
buflen = 2 * buflen - 1024;
|
||||||
|
#elif _STACK_GROWS_UP
|
||||||
|
if (old_buffer + buflen - 1024 == buffer)
|
||||||
|
{
|
||||||
|
buffer = old_buffer;
|
||||||
|
buflen = 2 * buflen - 1024;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (secure[hstdb])
|
if (secure[hstdb])
|
||||||
seteuid (oldeuid);
|
seteuid (oldeuid);
|
||||||
|
|
||||||
cache_addhst (db, fd, req, key, hst, uid);
|
cache_addhst (db, fd, req, key, hst, uid);
|
||||||
|
|
||||||
|
if (use_malloc)
|
||||||
|
free (buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -329,13 +364,14 @@ addhstbyaddr (struct database *db, int fd, request_header *req,
|
||||||
look again in the table whether the dataset is now available. We
|
look again in the table whether the dataset is now available. We
|
||||||
simply insert it. It does not matter if it is in there twice. The
|
simply insert it. It does not matter if it is in there twice. The
|
||||||
pruning function only will look at the timestamp. */
|
pruning function only will look at the timestamp. */
|
||||||
int buflen = 512;
|
int buflen = 1024;
|
||||||
char *buffer = alloca (buflen);
|
char *buffer = (char *) alloca (buflen);
|
||||||
struct hostent resultbuf;
|
struct hostent resultbuf;
|
||||||
struct hostent *hst;
|
struct hostent *hst;
|
||||||
uid_t oldeuid = 0;
|
uid_t oldeuid = 0;
|
||||||
|
bool use_malloc = false;
|
||||||
|
|
||||||
if (debug_level > 0)
|
if (__builtin_expect (debug_level > 0, 0))
|
||||||
{
|
{
|
||||||
char buf[INET_ADDRSTRLEN];
|
char buf[INET_ADDRSTRLEN];
|
||||||
dbg_log (_("Haven't found \"%s\" in hosts cache!"),
|
dbg_log (_("Haven't found \"%s\" in hosts cache!"),
|
||||||
|
@ -353,15 +389,47 @@ addhstbyaddr (struct database *db, int fd, request_header *req,
|
||||||
&& h_errno == NETDB_INTERNAL
|
&& h_errno == NETDB_INTERNAL
|
||||||
&& errno == ERANGE)
|
&& errno == ERANGE)
|
||||||
{
|
{
|
||||||
|
char *old_buffer = buffer;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
buflen += 256;
|
buflen += 1024;
|
||||||
buffer = alloca (buflen);
|
|
||||||
|
if (__builtin_expect (buflen > 32768, 0))
|
||||||
|
{
|
||||||
|
buffer = (char *) realloc (use_malloc ? buffer : NULL, buflen);
|
||||||
|
if (buffer == NULL)
|
||||||
|
{
|
||||||
|
/* We ran out of memory. We cannot do anything but
|
||||||
|
sending a negative response. In reality this should
|
||||||
|
never happen. */
|
||||||
|
hst = NULL;
|
||||||
|
buffer = old_buffer;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
use_malloc = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer = (char *) alloca (buflen);
|
||||||
|
#if _STACK_GROWS_DOWN
|
||||||
|
if (buffer + buflen == old_buffer)
|
||||||
|
buflen = 2 * buflen - 1024;
|
||||||
|
#elif _STACK_GROWS_UP
|
||||||
|
if (old_buffer + buflen - 1024 == buffer)
|
||||||
|
{
|
||||||
|
buffer = old_buffer;
|
||||||
|
buflen = 2 * buflen - 1024;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (secure[hstdb])
|
if (secure[hstdb])
|
||||||
seteuid (oldeuid);
|
seteuid (oldeuid);
|
||||||
|
|
||||||
cache_addhst (db, fd, req, key, hst, uid);
|
cache_addhst (db, fd, req, key, hst, uid);
|
||||||
|
|
||||||
|
if (use_malloc)
|
||||||
|
free (buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -373,13 +441,14 @@ addhstbynamev6 (struct database *db, int fd, request_header *req,
|
||||||
look again in the table whether the dataset is now available. We
|
look again in the table whether the dataset is now available. We
|
||||||
simply insert it. It does not matter if it is in there twice. The
|
simply insert it. It does not matter if it is in there twice. The
|
||||||
pruning function only will look at the timestamp. */
|
pruning function only will look at the timestamp. */
|
||||||
int buflen = 512;
|
int buflen = 1024;
|
||||||
char *buffer = alloca (buflen);
|
char *buffer = (char *) alloca (buflen);
|
||||||
struct hostent resultbuf;
|
struct hostent resultbuf;
|
||||||
struct hostent *hst;
|
struct hostent *hst;
|
||||||
uid_t oldeuid = 0;
|
uid_t oldeuid = 0;
|
||||||
|
bool use_malloc = false;
|
||||||
|
|
||||||
if (debug_level > 0)
|
if (__builtin_expect (debug_level > 0, 0))
|
||||||
{
|
{
|
||||||
char buf[INET6_ADDRSTRLEN];
|
char buf[INET6_ADDRSTRLEN];
|
||||||
|
|
||||||
|
@ -398,15 +467,47 @@ addhstbynamev6 (struct database *db, int fd, request_header *req,
|
||||||
&& h_errno == NETDB_INTERNAL
|
&& h_errno == NETDB_INTERNAL
|
||||||
&& errno == ERANGE)
|
&& errno == ERANGE)
|
||||||
{
|
{
|
||||||
|
char *old_buffer = buffer;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
buflen += 256;
|
buflen += 1024;
|
||||||
buffer = alloca (buflen);
|
|
||||||
|
if (__builtin_expect (buflen > 32768, 0))
|
||||||
|
{
|
||||||
|
buffer = (char *) realloc (use_malloc ? buffer : NULL, buflen);
|
||||||
|
if (buffer == NULL)
|
||||||
|
{
|
||||||
|
/* We ran out of memory. We cannot do anything but
|
||||||
|
sending a negative response. In reality this should
|
||||||
|
never happen. */
|
||||||
|
hst = NULL;
|
||||||
|
buffer = old_buffer;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
use_malloc = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer = (char *) alloca (buflen);
|
||||||
|
#if _STACK_GROWS_DOWN
|
||||||
|
if (buffer + buflen == old_buffer)
|
||||||
|
buflen = 2 * buflen - 1024;
|
||||||
|
#elif _STACK_GROWS_UP
|
||||||
|
if (old_buffer + buflen - 1024 == buffer)
|
||||||
|
{
|
||||||
|
buffer = old_buffer;
|
||||||
|
buflen = 2 * buflen - 1024;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (secure[hstdb])
|
if (secure[hstdb])
|
||||||
seteuid (oldeuid);
|
seteuid (oldeuid);
|
||||||
|
|
||||||
cache_addhst (db, fd, req, key, hst, uid);
|
cache_addhst (db, fd, req, key, hst, uid);
|
||||||
|
|
||||||
|
if (use_malloc)
|
||||||
|
free (buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -418,13 +519,14 @@ addhstbyaddrv6 (struct database *db, int fd, request_header *req,
|
||||||
look again in the table whether the dataset is now available. We
|
look again in the table whether the dataset is now available. We
|
||||||
simply insert it. It does not matter if it is in there twice. The
|
simply insert it. It does not matter if it is in there twice. The
|
||||||
pruning function only will look at the timestamp. */
|
pruning function only will look at the timestamp. */
|
||||||
int buflen = 512;
|
int buflen = 1024;
|
||||||
char *buffer = alloca (buflen);
|
char *buffer = (char *) alloca (buflen);
|
||||||
struct hostent resultbuf;
|
struct hostent resultbuf;
|
||||||
struct hostent *hst;
|
struct hostent *hst;
|
||||||
uid_t oldeuid = 0;
|
uid_t oldeuid = 0;
|
||||||
|
bool use_malloc = false;
|
||||||
|
|
||||||
if (debug_level > 0)
|
if (__builtin_expect (debug_level > 0, 0))
|
||||||
{
|
{
|
||||||
char buf[INET6_ADDRSTRLEN];
|
char buf[INET6_ADDRSTRLEN];
|
||||||
dbg_log (_("Haven't found \"%s\" in hosts cache!"),
|
dbg_log (_("Haven't found \"%s\" in hosts cache!"),
|
||||||
|
@ -442,13 +544,45 @@ addhstbyaddrv6 (struct database *db, int fd, request_header *req,
|
||||||
&& h_errno == NETDB_INTERNAL
|
&& h_errno == NETDB_INTERNAL
|
||||||
&& errno == ERANGE)
|
&& errno == ERANGE)
|
||||||
{
|
{
|
||||||
|
char *old_buffer = buffer;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
buflen += 256;
|
buflen += 1024;
|
||||||
buffer = alloca (buflen);
|
|
||||||
|
if (__builtin_expect (buflen > 32768, 0))
|
||||||
|
{
|
||||||
|
buffer = (char *) realloc (use_malloc ? buffer : NULL, buflen);
|
||||||
|
if (buffer == NULL)
|
||||||
|
{
|
||||||
|
/* We ran out of memory. We cannot do anything but
|
||||||
|
sending a negative response. In reality this should
|
||||||
|
never happen. */
|
||||||
|
hst = NULL;
|
||||||
|
buffer = old_buffer;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
use_malloc = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer = (char *) alloca (buflen);
|
||||||
|
#if _STACK_GROWS_DOWN
|
||||||
|
if (buffer + buflen == old_buffer)
|
||||||
|
buflen = 2 * buflen - 1024;
|
||||||
|
#elif _STACK_GROWS_UP
|
||||||
|
if (old_buffer + buflen - 1024 == buffer)
|
||||||
|
{
|
||||||
|
buffer = old_buffer;
|
||||||
|
buflen = 2 * buflen - 1024;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (secure[hstdb])
|
if (secure[hstdb])
|
||||||
seteuid (oldeuid);
|
seteuid (oldeuid);
|
||||||
|
|
||||||
cache_addhst (db, fd, req, key, hst, uid);
|
cache_addhst (db, fd, req, key, hst, uid);
|
||||||
|
|
||||||
|
if (use_malloc)
|
||||||
|
free (buffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* Cache handling for passwd lookup.
|
/* Cache handling for passwd lookup.
|
||||||
Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
|
Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
|
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <error.h>
|
#include <error.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -28,6 +29,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
|
#include <stackinfo.h>
|
||||||
|
|
||||||
#include "nscd.h"
|
#include "nscd.h"
|
||||||
#include "dbg_log.h"
|
#include "dbg_log.h"
|
||||||
|
@ -200,13 +202,14 @@ addpwbyname (struct database *db, int fd, request_header *req,
|
||||||
look again in the table whether the dataset is now available. We
|
look again in the table whether the dataset is now available. We
|
||||||
simply insert it. It does not matter if it is in there twice. The
|
simply insert it. It does not matter if it is in there twice. The
|
||||||
pruning function only will look at the timestamp. */
|
pruning function only will look at the timestamp. */
|
||||||
int buflen = 256;
|
int buflen = 1024;
|
||||||
char *buffer = alloca (buflen);
|
char *buffer = (char *) alloca (buflen);
|
||||||
struct passwd resultbuf;
|
struct passwd resultbuf;
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
uid_t oldeuid = 0;
|
uid_t oldeuid = 0;
|
||||||
|
bool use_malloc = false;
|
||||||
|
|
||||||
if (debug_level > 0)
|
if (__builtin_expect (debug_level > 0, 0))
|
||||||
dbg_log (_("Haven't found \"%s\" in password cache!"), (char *) key);
|
dbg_log (_("Haven't found \"%s\" in password cache!"), (char *) key);
|
||||||
|
|
||||||
if (secure[pwddb])
|
if (secure[pwddb])
|
||||||
|
@ -218,15 +221,47 @@ addpwbyname (struct database *db, int fd, request_header *req,
|
||||||
while (__getpwnam_r (key, &resultbuf, buffer, buflen, &pwd) != 0
|
while (__getpwnam_r (key, &resultbuf, buffer, buflen, &pwd) != 0
|
||||||
&& errno == ERANGE)
|
&& errno == ERANGE)
|
||||||
{
|
{
|
||||||
|
char *old_buffer = buffer;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
buflen += 256;
|
buflen += 1024;
|
||||||
buffer = alloca (buflen);
|
|
||||||
|
if (__builtin_expect (buflen > 32768, 0))
|
||||||
|
{
|
||||||
|
buffer = (char *) realloc (use_malloc ? buffer : NULL, buflen);
|
||||||
|
if (buffer == NULL)
|
||||||
|
{
|
||||||
|
/* We ran out of memory. We cannot do anything but
|
||||||
|
sending a negative response. In reality this should
|
||||||
|
never happen. */
|
||||||
|
pwd = NULL;
|
||||||
|
buffer = old_buffer;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
use_malloc = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer = (char *) alloca (buflen);
|
||||||
|
#if _STACK_GROWS_DOWN
|
||||||
|
if (buffer + buflen == old_buffer)
|
||||||
|
buflen = 2 * buflen - 1024;
|
||||||
|
#elif _STACK_GROWS_UP
|
||||||
|
if (old_buffer + buflen - 1024 == buffer)
|
||||||
|
{
|
||||||
|
buffer = old_buffer;
|
||||||
|
buflen = 2 * buflen - 1024;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (secure[pwddb])
|
if (secure[pwddb])
|
||||||
seteuid (oldeuid);
|
seteuid (oldeuid);
|
||||||
|
|
||||||
cache_addpw (db, fd, req, key, pwd, c_uid);
|
cache_addpw (db, fd, req, key, pwd, c_uid);
|
||||||
|
|
||||||
|
if (use_malloc)
|
||||||
|
free (buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -239,12 +274,13 @@ addpwbyuid (struct database *db, int fd, request_header *req,
|
||||||
simply insert it. It does not matter if it is in there twice. The
|
simply insert it. It does not matter if it is in there twice. The
|
||||||
pruning function only will look at the timestamp. */
|
pruning function only will look at the timestamp. */
|
||||||
int buflen = 256;
|
int buflen = 256;
|
||||||
char *buffer = alloca (buflen);
|
char *buffer = (char *) alloca (buflen);
|
||||||
struct passwd resultbuf;
|
struct passwd resultbuf;
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
uid_t oldeuid = 0;
|
uid_t oldeuid = 0;
|
||||||
char *ep;
|
char *ep;
|
||||||
uid_t uid = strtoul ((char *) key, &ep, 10);
|
uid_t uid = strtoul ((char *) key, &ep, 10);
|
||||||
|
bool use_malloc = false;
|
||||||
|
|
||||||
if (*(char *) key == '\0' || *ep != '\0') /* invalid numeric uid */
|
if (*(char *) key == '\0' || *ep != '\0') /* invalid numeric uid */
|
||||||
{
|
{
|
||||||
|
@ -255,7 +291,7 @@ addpwbyuid (struct database *db, int fd, request_header *req,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug_level > 0)
|
if (__builtin_expect (debug_level > 0, 0))
|
||||||
dbg_log (_("Haven't found \"%d\" in password cache!"), uid);
|
dbg_log (_("Haven't found \"%d\" in password cache!"), uid);
|
||||||
|
|
||||||
if (secure[pwddb])
|
if (secure[pwddb])
|
||||||
|
@ -267,13 +303,45 @@ addpwbyuid (struct database *db, int fd, request_header *req,
|
||||||
while (__getpwuid_r (uid, &resultbuf, buffer, buflen, &pwd) != 0
|
while (__getpwuid_r (uid, &resultbuf, buffer, buflen, &pwd) != 0
|
||||||
&& errno == ERANGE)
|
&& errno == ERANGE)
|
||||||
{
|
{
|
||||||
|
char *old_buffer = buffer;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
buflen += 256;
|
buflen += 1024;
|
||||||
buffer = alloca (buflen);
|
|
||||||
|
if (__builtin_expect (buflen > 32768, 0))
|
||||||
|
{
|
||||||
|
buffer = (char *) realloc (use_malloc ? buffer : NULL, buflen);
|
||||||
|
if (buffer == NULL)
|
||||||
|
{
|
||||||
|
/* We ran out of memory. We cannot do anything but
|
||||||
|
sending a negative response. In reality this should
|
||||||
|
never happen. */
|
||||||
|
pwd = NULL;
|
||||||
|
buffer = old_buffer;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
use_malloc = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer = (char *) alloca (buflen);
|
||||||
|
#if _STACK_GROWS_DOWN
|
||||||
|
if (buffer + buflen == old_buffer)
|
||||||
|
buflen = 2 * buflen - 1024;
|
||||||
|
#elif _STACK_GROWS_UP
|
||||||
|
if (old_buffer + buflen - 1024 == buffer)
|
||||||
|
{
|
||||||
|
buffer = old_buffer;
|
||||||
|
buflen = 2 * buflen - 1024;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (secure[pwddb])
|
if (secure[pwddb])
|
||||||
seteuid (oldeuid);
|
seteuid (oldeuid);
|
||||||
|
|
||||||
cache_addpw (db, fd, req, key, pwd, c_uid);
|
cache_addpw (db, fd, req, key, pwd, c_uid);
|
||||||
|
|
||||||
|
if (use_malloc)
|
||||||
|
free (buffer);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue