(_nss_hesiod_initgroups_dyn): Correctly handle numeric group member information. Complete test for strtol overflow.

This commit is contained in:
Ulrich Drepper 2000-10-20 06:33:30 +00:00
parent aab0963999
commit 521a2f6584
1 changed files with 15 additions and 3 deletions

View File

@ -174,6 +174,7 @@ _nss_hesiod_initgroups_dyn (const char *user, gid_t group, long int *start,
char *p; char *p;
void *context; void *context;
gid_t *groups = *groupsp; gid_t *groups = *groupsp;
int save_errno;
context = _nss_hesiod_init (); context = _nss_hesiod_init ();
if (context == NULL) if (context == NULL)
@ -214,6 +215,8 @@ _nss_hesiod_initgroups_dyn (const char *user, gid_t group, long int *start,
groups[(*start)++] = group; groups[(*start)++] = group;
} }
save_errno = errno;
p = *list; p = *list;
while (*p != '\0') while (*p != '\0')
{ {
@ -224,17 +227,24 @@ _nss_hesiod_initgroups_dyn (const char *user, gid_t group, long int *start,
status = NSS_STATUS_NOTFOUND; status = NSS_STATUS_NOTFOUND;
q = p; q = p;
while (*q != '\0' && *q != ':') while (*q != '\0' && *q != ':' && *q != ',')
++q; ++q;
if (*q != '\0') if (*q != '\0')
*q++ = '\0'; *q++ = '\0';
__set_errno (0);
val = strtol (p, &endp, 10); val = strtol (p, &endp, 10);
if (sizeof (gid_t) == sizeof (long int) || (gid_t) val == val) /* Test whether the number is representable in a variable of
type `gid_t'. If not ignore the number. */
if ((sizeof (gid_t) == sizeof (long int) || (gid_t) val == val)
&& errno == 0)
{ {
if (*endp == '\0' && endp != p) if (*endp == '\0' && endp != p)
status = NSS_STATUS_SUCCESS; {
group = val;
status = NSS_STATUS_SUCCESS;
}
else else
status = internal_gid_from_group (context, p, &group); status = internal_gid_from_group (context, p, &group);
@ -270,6 +280,8 @@ _nss_hesiod_initgroups_dyn (const char *user, gid_t group, long int *start,
p = q; p = q;
} }
__set_errno (save_errno);
done: done:
hesiod_free_list (context, list); hesiod_free_list (context, list);
hesiod_end (context); hesiod_end (context);