2004-10-05  Ulrich Drepper  <drepper@redhat.com>

	* grp/initgroups.c: Remove duplicate group IDs.
	* grp/compat-initgroups.c: Likewise.
	* nscd/initgrcache.c: Likewise.
This commit is contained in:
Ulrich Drepper 2004-10-05 15:36:41 +00:00
parent 6ab5f50de4
commit 695c43708f
4 changed files with 74 additions and 24 deletions

View File

@ -1,3 +1,9 @@
2004-10-05 Ulrich Drepper <drepper@redhat.com>
* grp/initgroups.c: Remove duplicate group IDs.
* grp/compat-initgroups.c: Likewise.
* nscd/initgrcache.c: Likewise.
2004-10-05 Jakub Jelinek <jakub@redhat.com> 2004-10-05 Jakub Jelinek <jakub@redhat.com>
* sysdeps/unix/sysv/linux/x86_64/sysconf.c (__sysconf): Return 200112L * sysdeps/unix/sysv/linux/x86_64/sysconf.c (__sysconf): Return 200112L

View File

@ -58,31 +58,42 @@ compat_call (service_user *nip, const char *user, gid_t group, long int *start,
for (m = grpbuf.gr_mem; *m != NULL; ++m) for (m = grpbuf.gr_mem; *m != NULL; ++m)
if (strcmp (*m, user) == 0) if (strcmp (*m, user) == 0)
{ {
/* Matches user. Insert this group. */ /* Check whether the group is already on the list. */
if (__builtin_expect (*start == *size, 0)) long int cnt;
{ for (cnt = 0; cnt < *start; ++cnt)
/* Need a bigger buffer. */ if (groups[cnt] == grpbuf.gr_gid)
gid_t *newgroups; break;
long int newsize;
if (limit > 0 && *size == limit) if (cnt == *start)
/* We reached the maximum. */ {
goto done; /* Matches user and not yet on the list. Insert
this group. */
if (__builtin_expect (*start == *size, 0))
{
/* Need a bigger buffer. */
gid_t *newgroups;
long int newsize;
if (limit <= 0) if (limit > 0 && *size == limit)
newsize = 2 * *size; /* We reached the maximum. */
else goto done;
newsize = MIN (limit, 2 * *size);
newgroups = realloc (groups, newsize * sizeof (*groups)); if (limit <= 0)
if (newgroups == NULL) newsize = 2 * *size;
goto done; else
*groupsp = groups = newgroups; newsize = MIN (limit, 2 * *size);
*size = newsize;
}
groups[*start] = grpbuf.gr_gid; newgroups = realloc (groups,
*start += 1; newsize * sizeof (*groups));
if (newgroups == NULL)
goto done;
*groupsp = groups = newgroups;
*size = newsize;
}
groups[*start] = grpbuf.gr_gid;
*start += 1;
}
break; break;
} }

View File

@ -73,7 +73,7 @@ internal_getgrouplist (const char *user, gid_t group, long int *size,
/* Start is one, because we have the first group as parameter. */ /* Start is one, because we have the first group as parameter. */
long int start = 1; long int start = 1;
*groupsp[0] = group; (*groupsp)[0] = group;
if (__nss_group_database != NULL) if (__nss_group_database != NULL)
{ {
@ -86,6 +86,8 @@ internal_getgrouplist (const char *user, gid_t group, long int *size,
while (! no_more) while (! no_more)
{ {
long int prev_start = start;
fct = __nss_lookup_function (nip, "initgroups_dyn"); fct = __nss_lookup_function (nip, "initgroups_dyn");
if (fct == NULL) if (fct == NULL)
@ -100,6 +102,21 @@ internal_getgrouplist (const char *user, gid_t group, long int *size,
status = DL_CALL_FCT (fct, (user, group, &start, size, groupsp, status = DL_CALL_FCT (fct, (user, group, &start, size, groupsp,
limit, &errno)); limit, &errno));
/* Remove duplicates. */
long int cnt = prev_start;
while (cnt < start)
{
long int inner;
for (inner = 0; inner < prev_start; ++inner)
if ((*groupsp)[inner] == (*groupsp)[cnt])
break;
if (inner < prev_start)
(*groupsp)[cnt] = (*groupsp)[--start];
else
++cnt;
}
/* This is really only for debugging. */ /* This is really only for debugging. */
if (NSS_STATUS_TRYAGAIN > status || status > NSS_STATUS_RETURN) if (NSS_STATUS_TRYAGAIN > status || status > NSS_STATUS_RETURN)
__libc_fatal ("illegal status in internal_getgrouplist"); __libc_fatal ("illegal status in internal_getgrouplist");
@ -124,10 +141,10 @@ int
getgrouplist (const char *user, gid_t group, gid_t *groups, int *ngroups) getgrouplist (const char *user, gid_t group, gid_t *groups, int *ngroups)
{ {
gid_t *newgroups; gid_t *newgroups;
long int size = *ngroups; long int size = MAX (1, *ngroups);
int result; int result;
newgroups = (gid_t *) malloc (size * sizeof (gid_t)); newgroups = (gid_t *) malloc ((size + 1) * sizeof (gid_t));
if (__builtin_expect (newgroups == NULL, 0)) if (__builtin_expect (newgroups == NULL, 0))
/* No more memory. */ /* No more memory. */
// XXX This is wrong. The user provided memory, we have to use // XXX This is wrong. The user provided memory, we have to use

View File

@ -117,6 +117,7 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
/* Nothing added yet. */ /* Nothing added yet. */
while (! no_more) while (! no_more)
{ {
long int prev_start = start;
enum nss_status status; enum nss_status status;
initgroups_dyn_function fct; initgroups_dyn_function fct;
fct = __nss_lookup_function (nip, "initgroups_dyn"); fct = __nss_lookup_function (nip, "initgroups_dyn");
@ -133,6 +134,21 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
status = DL_CALL_FCT (fct, (key, -1, &start, &size, &groups, status = DL_CALL_FCT (fct, (key, -1, &start, &size, &groups,
limit, &errno)); limit, &errno));
/* Remove duplicates. */
long int cnt = prev_start;
while (cnt < start)
{
long int inner;
for (inner = 0; inner < prev_start; ++inner)
if (groups[inner] == groups[cnt])
break;
if (inner < prev_start)
groups[cnt] = groups[--start];
else
++cnt;
}
if (status != NSS_STATUS_TRYAGAIN) if (status != NSS_STATUS_TRYAGAIN)
all_tryagain = false; all_tryagain = false;