* nis/nss_nis/nis-alias.c: Optimize use of yperr2nss. Avoid calling

it for YPERR_SUCCESS.  Minor cleanups.  Add __builtin_expect.
	* nis/nss_nis/nis-ethers.c: Likewise.
	* nis/nss_nis/nis-grp.c: Likewise.
	* nis/nss_nis/nis-hosts.c: Likewise.
	* nis/nss_nis/nis-initgroups.c: Likewise.
	* nis/nss_nis/nis-netgrp.c: Likewise.
	* nis/nss_nis/nis-network.c: Likewise.
	* nis/nss_nis/nis-proto.c: Likewise.
	* nis/nss_nis/nis-publickey.c: Likewise.
	* nis/nss_nis/nis-pwd.c: Likewise.
	* nis/nss_nis/nis-rpc.c: Likewise.
	* nis/nss_nis/nis-service.c: Likewise.
	* nis/nss_nis/nis-spwd.c: Likewise.
This commit is contained in:
Ulrich Drepper 2006-04-09 02:45:24 +00:00
parent 7960f2a704
commit ab9a9ff8a1
22 changed files with 531 additions and 509 deletions

View File

@ -1,5 +1,20 @@
2006-04-08 Ulrich Drepper <drepper@redhat.com> 2006-04-08 Ulrich Drepper <drepper@redhat.com>
* nis/nss_nis/nis-alias.c: Optimize use of yperr2nss. Avoid calling
it for YPERR_SUCCESS. Minor cleanups. Add __builtin_expect.
* nis/nss_nis/nis-ethers.c: Likewise.
* nis/nss_nis/nis-grp.c: Likewise.
* nis/nss_nis/nis-hosts.c: Likewise.
* nis/nss_nis/nis-initgroups.c: Likewise.
* nis/nss_nis/nis-netgrp.c: Likewise.
* nis/nss_nis/nis-network.c: Likewise.
* nis/nss_nis/nis-proto.c: Likewise.
* nis/nss_nis/nis-publickey.c: Likewise.
* nis/nss_nis/nis-pwd.c: Likewise.
* nis/nss_nis/nis-rpc.c: Likewise.
* nis/nss_nis/nis-service.c: Likewise.
* nis/nss_nis/nis-spwd.c: Likewise.
* nis/nis_ping.c: Remove unnecessary conditionals before * nis/nis_ping.c: Remove unnecessary conditionals before
nis_freeresult calls. nis_freeresult calls.
* nis/nis_ismember.c: Likewise. * nis/nis_ismember.c: Likewise.

View File

@ -125,52 +125,53 @@ internal_nis_getaliasent_r (struct aliasent *alias, char *buffer,
size_t buflen, int *errnop) size_t buflen, int *errnop)
{ {
char *domain; char *domain;
char *result;
int len;
char *outkey;
int keylen;
char *p;
int parse_res;
if (yp_get_default_domain (&domain)) if (__builtin_expect (yp_get_default_domain (&domain), 0))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
alias->alias_local = 0; alias->alias_local = 0;
/* Get the next entry until we found a correct one. */ /* Get the next entry until we found a correct one. */
int parse_res;
do do
{ {
enum nss_status retval; char *result;
int len;
char *outkey;
int keylen;
int yperr;
if (new_start) if (new_start)
retval = yperr2nss (yp_first (domain, "mail.aliases", yperr = yp_first (domain, "mail.aliases", &outkey, &keylen, &result,
&outkey, &keylen, &result, &len)); &len);
else else
retval = yperr2nss ( yp_next (domain, "mail.aliases", oldkey, yperr = yp_next (domain, "mail.aliases", oldkey, oldkeylen, &outkey,
oldkeylen, &outkey, &keylen, &keylen, &result, &len);
&result, &len));
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
} }
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_nis_parse_aliasent (outkey, p, alias, buffer, buflen, parse_res = _nss_nis_parse_aliasent (outkey, p, alias, buffer,
errnop); buflen, errnop);
if (parse_res == -1) if (__builtin_expect (parse_res == -1, 0))
{ {
free (outkey); free (outkey);
*errnop = ERANGE; *errnop = ERANGE;
@ -216,7 +217,7 @@ _nss_nis_getaliasbyname_r (const char *name, struct aliasent *alias,
char name2[namlen + 1]; char name2[namlen + 1];
char *domain; char *domain;
if (yp_get_default_domain (&domain)) if (__builtin_expect (yp_get_default_domain (&domain), 0))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
/* Convert name to lowercase. */ /* Convert name to lowercase. */
@ -227,17 +228,18 @@ _nss_nis_getaliasbyname_r (const char *name, struct aliasent *alias,
char *result; char *result;
int len; int len;
enum nss_status retval = yperr2nss (yp_match (domain, "mail.aliases", name2, int yperr = yp_match (domain, "mail.aliases", name2, namlen, &result, &len);
namlen, &result, &len));
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
} }
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
@ -253,7 +255,7 @@ _nss_nis_getaliasbyname_r (const char *name, struct aliasent *alias,
alias->alias_local = 0; alias->alias_local = 0;
int parse_res = _nss_nis_parse_aliasent (name, p, alias, buffer, buflen, int parse_res = _nss_nis_parse_aliasent (name, p, alias, buffer, buflen,
errnop); errnop);
if (parse_res < 1) if (__builtin_expect (parse_res < 1, 0))
{ {
if (parse_res == -1) if (parse_res == -1)
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1996-2003, 2004 Free Software Foundation, Inc. /* Copyright (C) 1996-2003, 2004, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@ -182,45 +182,46 @@ enum nss_status
_nss_nis_gethostton_r (const char *name, struct etherent *eth, _nss_nis_gethostton_r (const char *name, struct etherent *eth,
char *buffer, size_t buflen, int *errnop) char *buffer, size_t buflen, int *errnop)
{ {
struct parser_data *data = (void *) buffer;
enum nss_status retval;
char *domain, *result, *p;
int len, parse_res;
if (name == NULL) if (name == NULL)
{ {
*errnop = EINVAL; *errnop = EINVAL;
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
} }
if (yp_get_default_domain (&domain)) char *domain;
if (__builtin_expect (yp_get_default_domain (&domain), 0))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
retval = yperr2nss (yp_match (domain, "ethers.byname", name, char *result;
strlen (name), &result, &len)); int len;
int yperr = yp_match (domain, "ethers.byname", name, strlen (name), &result,
&len);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
} }
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_etherent (p, eth, data, buflen, errnop); int parse_res = _nss_files_parse_etherent (p, eth, (void *) buffer, buflen,
if (parse_res < 1) errnop);
if (__builtin_expect (parse_res < 1, 0))
{ {
if (parse_res == -1) if (parse_res == -1)
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
@ -234,54 +235,54 @@ enum nss_status
_nss_nis_getntohost_r (const struct ether_addr *addr, struct etherent *eth, _nss_nis_getntohost_r (const struct ether_addr *addr, struct etherent *eth,
char *buffer, size_t buflen, int *errnop) char *buffer, size_t buflen, int *errnop)
{ {
struct parser_data *data = (void *) buffer;
enum nss_status retval;
char *domain, *result, *p;
int len, nlen, parse_res;
char buf[33];
if (addr == NULL) if (addr == NULL)
{ {
*errnop = EINVAL; *errnop = EINVAL;
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
} }
if (yp_get_default_domain (&domain)) char *domain;
if (__builtin_expect (yp_get_default_domain (&domain), 0))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
nlen = sprintf (buf, "%x:%x:%x:%x:%x:%x", char buf[33];
(int) addr->ether_addr_octet[0], int nlen = snprintf (buf, sizeof (buf), "%x:%x:%x:%x:%x:%x",
(int) addr->ether_addr_octet[1], (int) addr->ether_addr_octet[0],
(int) addr->ether_addr_octet[2], (int) addr->ether_addr_octet[1],
(int) addr->ether_addr_octet[3], (int) addr->ether_addr_octet[2],
(int) addr->ether_addr_octet[4], (int) addr->ether_addr_octet[3],
(int) addr->ether_addr_octet[5]); (int) addr->ether_addr_octet[4],
(int) addr->ether_addr_octet[5]);
retval = yperr2nss (yp_match (domain, "ethers.byaddr", buf, char *result;
nlen, &result, &len)); int len;
int yperr = yp_match (domain, "ethers.byaddr", buf, nlen, &result, &len);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
} }
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_etherent (p, eth, data, buflen, errnop); int parse_res = _nss_files_parse_etherent (p, eth, (void *) buffer, buflen,
if (parse_res < 1) errnop);
if (__builtin_expect (parse_res < 1, 0))
{ {
if (parse_res == -1) if (parse_res == -1)
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1996-1999, 2001-2003, 2004 Free Software Foundation, Inc. /* Copyright (C) 1996-1999, 2001-2003, 2004, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@ -71,49 +71,52 @@ static enum nss_status
internal_nis_getgrent_r (struct group *grp, char *buffer, size_t buflen, internal_nis_getgrent_r (struct group *grp, char *buffer, size_t buflen,
int *errnop) int *errnop)
{ {
struct parser_data *data = (void *) buffer; char *domain;
char *domain, *result, *outkey; if (__builtin_expect (yp_get_default_domain (&domain), 0))
int len, keylen, parse_res;
if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
/* Get the next entry until we found a correct one. */ /* Get the next entry until we found a correct one. */
int parse_res;
do do
{ {
enum nss_status retval; char *result;
char *p; char *outkey;
int len;
int keylen;
int yperr;
if (new_start) if (new_start)
retval = yperr2nss (yp_first (domain, "group.byname", yperr = yp_first (domain, "group.byname", &outkey, &keylen, &result,
&outkey, &keylen, &result, &len)); &len);
else else
retval = yperr2nss ( yp_next (domain, "group.byname", yperr = yp_next (domain, "group.byname", oldkey, oldkeylen, &outkey,
oldkey, oldkeylen, &keylen, &result, &len);
&outkey, &keylen, &result, &len));
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
} }
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_grent (p, grp, data, buflen, errnop); parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
if (parse_res == -1) errnop);
if (__builtin_expect (parse_res == -1, 0))
{ {
free (outkey); free (outkey);
*errnop = ERANGE; *errnop = ERANGE;
@ -149,45 +152,46 @@ enum nss_status
_nss_nis_getgrnam_r (const char *name, struct group *grp, _nss_nis_getgrnam_r (const char *name, struct group *grp,
char *buffer, size_t buflen, int *errnop) char *buffer, size_t buflen, int *errnop)
{ {
struct parser_data *data = (void *) buffer;
enum nss_status retval;
char *domain, *result, *p;
int len, parse_res;
if (name == NULL) if (name == NULL)
{ {
*errnop = EINVAL; *errnop = EINVAL;
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
} }
if (yp_get_default_domain (&domain)) char *domain;
if (__builtin_expect (yp_get_default_domain (&domain), 0))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
retval = yperr2nss (yp_match (domain, "group.byname", name, char *result;
strlen (name), &result, &len)); int len;
int yperr = yp_match (domain, "group.byname", name, strlen (name), &result,
&len);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
} }
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_grent (p, grp, data, buflen, errnop); int parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
if (parse_res < 1) errnop);
if (__builtin_expect (parse_res < 1, 0))
{ {
if (parse_res == -1) if (parse_res == -1)
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
@ -201,42 +205,42 @@ enum nss_status
_nss_nis_getgrgid_r (gid_t gid, struct group *grp, _nss_nis_getgrgid_r (gid_t gid, struct group *grp,
char *buffer, size_t buflen, int *errnop) char *buffer, size_t buflen, int *errnop)
{ {
struct parser_data *data = (void *) buffer; char *domain;
enum nss_status retval; if (__builtin_expect (yp_get_default_domain (&domain), 0))
char *domain, *result, *p;
int len, nlen, parse_res;
char buf[32];
if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
nlen = sprintf (buf, "%lu", (unsigned long int) gid); char buf[32];
int nlen = sprintf (buf, "%lu", (unsigned long int) gid);
retval = yperr2nss (yp_match (domain, "group.bygid", buf, char *result;
nlen, &result, &len)); int len;
int yperr = yp_match (domain, "group.bygid", buf, nlen, &result, &len);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
} }
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_grent (p, grp, data, buflen, errnop); int parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
if (parse_res < 1) errnop);
if (__builtin_expect (parse_res < 1, 0))
{ {
if (parse_res == -1) if (parse_res == -1)
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1996-2000, 2002, 2003 Free Software Foundation, Inc. /* Copyright (C) 1996-2000, 2002, 2003, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@ -131,17 +131,11 @@ internal_nis_gethostent_r (struct hostent *host, char *buffer,
int af, int flags) int af, int flags)
{ {
char *domain; char *domain;
char *result; if (__builtin_expect (yp_get_default_domain (&domain), 0))
int len, parse_res;
char *outkey;
int keylen;
struct parser_data *data = (void *) buffer;
size_t linebuflen = buffer + buflen - data->linebuffer;
if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
if (buflen < sizeof *data + 1) struct parser_data *data = (void *) buffer;
if (__builtin_expect (buflen < sizeof *data + 1, 0))
{ {
*errnop = ERANGE; *errnop = ERANGE;
*h_errnop = NETDB_INTERNAL; *h_errnop = NETDB_INTERNAL;
@ -149,21 +143,26 @@ internal_nis_gethostent_r (struct hostent *host, char *buffer,
} }
/* Get the next entry until we found a correct one. */ /* Get the next entry until we found a correct one. */
const size_t linebuflen = buffer + buflen - data->linebuffer;
int parse_res;
do do
{ {
enum nss_status retval; char *result;
char *p; int len;
char *outkey;
int keylen;
int yperr;
if (new_start) if (new_start)
retval = yperr2nss (yp_first (domain, "hosts.byname", yperr = yp_first (domain, "hosts.byname", &outkey, &keylen, &result,
&outkey, &keylen, &result, &len)); &len);
else else
retval = yperr2nss ( yp_next (domain, "hosts.byname", yperr = yp_next (domain, "hosts.byname", oldkey, oldkeylen, &outkey,
oldkey, oldkeylen, &keylen, &result, &len);
&outkey, &keylen, &result, &len));
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
switch (retval) switch (retval)
{ {
case NSS_STATUS_TRYAGAIN: case NSS_STATUS_TRYAGAIN:
@ -180,7 +179,7 @@ internal_nis_gethostent_r (struct hostent *host, char *buffer,
return retval; return retval;
} }
if ((size_t) (len + 1) > linebuflen) if (__builtin_expect ((size_t) (len + 1) > linebuflen, 0))
{ {
free (result); free (result);
*h_errnop = NETDB_INTERNAL; *h_errnop = NETDB_INTERNAL;
@ -188,14 +187,14 @@ internal_nis_gethostent_r (struct hostent *host, char *buffer,
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (data->linebuffer, result, len); char *p = strncpy (data->linebuffer, result, len);
data->linebuffer[len] = '\0'; data->linebuffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = parse_line (p, host, data, buflen, errnop, af, flags); parse_res = parse_line (p, host, data, buflen, errnop, af, flags);
if (parse_res == -1) if (__builtin_expect (parse_res == -1, 0))
{ {
free (outkey); free (outkey);
*h_errnop = NETDB_INTERNAL; *h_errnop = NETDB_INTERNAL;
@ -235,11 +234,7 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
char *buffer, size_t buflen, int *errnop, char *buffer, size_t buflen, int *errnop,
int *h_errnop, int flags) int *h_errnop, int flags)
{ {
enum nss_status retval;
char *domain, *result, *p;
int len, parse_res;
struct parser_data *data = (void *) buffer; struct parser_data *data = (void *) buffer;
size_t linebuflen = buffer + buflen - data->linebuffer;
if (name == NULL) if (name == NULL)
{ {
@ -247,6 +242,7 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
} }
char *domain;
if (yp_get_default_domain (&domain)) if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
@ -256,24 +252,24 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
*errnop = ERANGE; *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
else
/* Convert name to lowercase. */
size_t namlen = strlen (name);
char name2[namlen + 1];
size_t i;
for (i = 0; i < namlen; ++i)
name2[i] = tolower (name[i]);
name2[i] = '\0';
char *result;
int len;
int yperr = yp_match (domain, "hosts.byname", name2, namlen, &result, &len);
if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
/* Convert name to lowercase. */ enum nss_status retval = yperr2nss (yperr);
size_t namlen = strlen (name);
char name2[namlen + 1];
size_t i;
for (i = 0; i < namlen; ++i)
name2[i] = tolower (name[i]);
name2[i] = '\0';
retval = yperr2nss (yp_match (domain, "hosts.byname", name2,
namlen, &result, &len));
}
if (retval != NSS_STATUS_SUCCESS)
{
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
{ {
*h_errnop = TRY_AGAIN; *h_errnop = TRY_AGAIN;
@ -284,7 +280,8 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
return retval; return retval;
} }
if ((size_t) (len + 1) > linebuflen) const size_t linebuflen = buffer + buflen - data->linebuffer;
if (__builtin_expect ((size_t) (len + 1) > linebuflen, 0))
{ {
free (result); free (result);
*h_errnop = NETDB_INTERNAL; *h_errnop = NETDB_INTERNAL;
@ -292,15 +289,15 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (data->linebuffer, result, len); char *p = strncpy (data->linebuffer, result, len);
data->linebuffer[len] = '\0'; data->linebuffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = parse_line (p, host, data, buflen, errnop, af, flags); int parse_res = parse_line (p, host, data, buflen, errnop, af, flags);
if (parse_res < 1 || host->h_addrtype != af) if (__builtin_expect (parse_res < 1 || host->h_addrtype != af, 0))
{ {
if (parse_res == -1) if (parse_res == -1)
{ {
@ -351,42 +348,42 @@ _nss_nis_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
struct hostent *host, char *buffer, size_t buflen, struct hostent *host, char *buffer, size_t buflen,
int *errnop, int *h_errnop) int *errnop, int *h_errnop)
{ {
enum nss_status retval; char *domain;
char *domain, *result, *p; if (__builtin_expect (yp_get_default_domain (&domain), 0))
int len, parse_res;
char *buf;
struct parser_data *data = (void *) buffer;
size_t linebuflen = buffer + buflen - data->linebuffer;
if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
if (buflen < sizeof *data + 1) struct parser_data *data = (void *) buffer;
if (__builtin_expect (buflen < sizeof *data + 1, 0))
{ {
*errnop = ERANGE; *errnop = ERANGE;
*h_errnop = NETDB_INTERNAL; *h_errnop = NETDB_INTERNAL;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
buf = inet_ntoa (*(const struct in_addr *) addr); char *buf = inet_ntoa (*(const struct in_addr *) addr);
retval = yperr2nss (yp_match (domain, "hosts.byaddr", buf, char *result;
strlen (buf), &result, &len)); int len;
int yperr = yp_match (domain, "hosts.byaddr", buf, strlen (buf), &result,
&len);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
{ {
*h_errnop = TRY_AGAIN; *h_errnop = TRY_AGAIN;
*errnop = errno; *errnop = errno;
} }
if (retval == NSS_STATUS_NOTFOUND) else if (retval == NSS_STATUS_NOTFOUND)
*h_errnop = HOST_NOT_FOUND; *h_errnop = HOST_NOT_FOUND;
return retval; return retval;
} }
if ((size_t) (len + 1) > linebuflen) const size_t linebuflen = buffer + buflen - data->linebuffer;
if (__builtin_expect ((size_t) (len + 1) > linebuflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
@ -394,15 +391,16 @@ _nss_nis_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (data->linebuffer, result, len); char *p = strncpy (data->linebuffer, result, len);
data->linebuffer[len] = '\0'; data->linebuffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = parse_line (p, host, data, buflen, errnop, af, int parse_res = parse_line (p, host, data, buflen, errnop, af,
((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0)); ((_res.options & RES_USE_INET6)
if (parse_res < 1) ? AI_V4MAPPED : 0));
if (__builtin_expect (parse_res < 1, 0))
{ {
if (parse_res == -1) if (parse_res == -1)
{ {

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1998-2000, 2002, 2003, 2004 Free Software Foundation, Inc. /* Copyright (C) 1998-2000,2002,2003,2004,2006 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
@ -99,25 +99,23 @@ static enum nss_status
internal_getgrent_r (struct group *grp, char *buffer, size_t buflen, internal_getgrent_r (struct group *grp, char *buffer, size_t buflen,
int *errnop, intern_t *intern) int *errnop, intern_t *intern)
{ {
struct parser_data *data = (void *) buffer;
int parse_res;
char *p;
if (intern->start == NULL) if (intern->start == NULL)
return NSS_STATUS_NOTFOUND; return NSS_STATUS_NOTFOUND;
/* Get the next entry until we found a correct one. */ /* Get the next entry until we found a correct one. */
int parse_res;
do do
{ {
if (intern->next == NULL) if (intern->next == NULL)
return NSS_STATUS_NOTFOUND; return NSS_STATUS_NOTFOUND;
p = strncpy (buffer, intern->next->val, buflen); char *p = strncpy (buffer, intern->next->val, buflen);
while (isspace (*p)) while (isspace (*p))
++p; ++p;
parse_res = _nss_files_parse_grent (p, grp, data, buflen, errnop); parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
if (parse_res == -1) errnop);
if (__builtin_expect (parse_res == -1, 0))
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
intern->next = intern->next->next; intern->next = intern->next->next;
} }
@ -166,13 +164,12 @@ initgroups_netid (uid_t uid, gid_t group, long int *start, long int *size,
ssize_t keylen = snprintf (key, sizeof (key), "unix.%lu@%s", ssize_t keylen = snprintf (key, sizeof (key), "unix.%lu@%s",
(unsigned long int) uid, domainname); (unsigned long int) uid, domainname);
enum nss_status retval;
char *result; char *result;
int reslen; int reslen;
retval = yperr2nss (yp_match (domainname, "netid.byname", key, keylen, int yperr = yp_match (domainname, "netid.byname", key, keylen, &result,
&result, &reslen)); &reslen);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
return retval; return yperr2nss (yperr);
/* Parse the result: following the colon is a comma separated list of /* Parse the result: following the colon is a comma separated list of
group IDs. */ group IDs. */
@ -207,7 +204,6 @@ initgroups_netid (uid_t uid, gid_t group, long int *start, long int *size,
if (*start == *size) if (*start == *size)
{ {
/* Need a bigger buffer. */ /* Need a bigger buffer. */
gid_t *newgroups;
long int newsize; long int newsize;
if (limit > 0 && *size == limit) if (limit > 0 && *size == limit)
@ -219,7 +215,7 @@ initgroups_netid (uid_t uid, gid_t group, long int *start, long int *size,
else else
newsize = MIN (limit, 2 * *size); newsize = MIN (limit, 2 * *size);
newgroups = realloc (groups, newsize * sizeof (*groups)); gid_t *newgroups = realloc (groups, newsize * sizeof (*groups));
if (newgroups == NULL) if (newgroups == NULL)
goto errout; goto errout;
*groupsp = groups = newgroups; *groupsp = groups = newgroups;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1996,1997,1999,2000,2002,2003,2004,2005 /* Copyright (C) 1996,1997,1999,2000,2002,2003,2004,2005,2006
Free Software Foundation, Inc. Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@ -47,24 +47,25 @@ internal_nis_endnetgrent (struct __netgrent *netgrp)
netgrp->cursor = NULL; netgrp->cursor = NULL;
} }
enum nss_status enum nss_status
_nss_nis_setnetgrent (const char *group, struct __netgrent *netgrp) _nss_nis_setnetgrent (const char *group, struct __netgrent *netgrp)
{ {
char *domain;
int len; int len;
enum nss_status status; enum nss_status status;
status = NSS_STATUS_SUCCESS; status = NSS_STATUS_SUCCESS;
if (group == NULL || group[0] == '\0') if (__builtin_expect (group == NULL || group[0] == '\0', 0))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
if (yp_get_default_domain (&domain)) char *domain;
if (__builtin_expect (yp_get_default_domain (&domain), 0))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
status = yperr2nss (yp_match (domain, "netgroup", group, strlen (group), status = yperr2nss (yp_match (domain, "netgroup", group, strlen (group),
&netgrp->data, &len)); &netgrp->data, &len));
if (status == NSS_STATUS_SUCCESS) if (__builtin_expect (status == NSS_STATUS_SUCCESS, 1))
{ {
/* Our implementation of yp_match already allocates a buffer /* Our implementation of yp_match already allocates a buffer
which is one byte larger than the value in LEN specifies which is one byte larger than the value in LEN specifies
@ -90,6 +91,7 @@ _nss_nis_endnetgrent (struct __netgrent *netgrp)
return NSS_STATUS_SUCCESS; return NSS_STATUS_SUCCESS;
} }
enum nss_status enum nss_status
_nss_nis_getnetgrent_r (struct __netgrent *result, char *buffer, size_t buflen, _nss_nis_getnetgrent_r (struct __netgrent *result, char *buffer, size_t buflen,
int *errnop) int *errnop)

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1996-2000, 2001, 2002, 2003 Free Software Foundation, Inc. /* Copyright (C) 1996-2003, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996. Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
@ -73,28 +73,32 @@ internal_nis_getnetent_r (struct netent *net, char *buffer, size_t buflen,
int *errnop, int *herrnop) int *errnop, int *herrnop)
{ {
struct parser_data *data = (void *) buffer; struct parser_data *data = (void *) buffer;
char *domain, *result, *outkey;
int len, keylen, parse_res;
if (yp_get_default_domain (&domain)) char *domain;
if (__builtin_expect (yp_get_default_domain (&domain), 0))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
/* Get the next entry until we found a correct one. */ /* Get the next entry until we found a correct one. */
int parse_res;
do do
{ {
enum nss_status retval; char *result;
char *p; char *outkey;
int len;
int keylen;
int yperr;
if (new_start) if (new_start)
retval = yperr2nss (yp_first (domain, "networks.byname", yperr = yp_first (domain, "networks.byname", &outkey, &keylen, &result,
&outkey, &keylen, &result, &len)); &len);
else else
retval = yperr2nss ( yp_next (domain, "networks.byname", yperr = yp_next (domain, "networks.byname", oldkey, oldkeylen, &outkey,
oldkey, oldkeylen, &keylen, &result, &len);
&outkey, &keylen, &result, &len));
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
{ {
*herrnop = NETDB_INTERNAL; *herrnop = NETDB_INTERNAL;
@ -103,7 +107,7 @@ internal_nis_getnetent_r (struct netent *net, char *buffer, size_t buflen,
return retval; return retval;
} }
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
@ -111,14 +115,14 @@ internal_nis_getnetent_r (struct netent *net, char *buffer, size_t buflen,
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_netent (p, net, data, buflen, errnop); parse_res = _nss_files_parse_netent (p, net, data, buflen, errnop);
if (parse_res == -1) if (__builtin_expect (parse_res == -1, 0))
{ {
free (outkey); free (outkey);
*herrnop = NETDB_INTERNAL; *herrnop = NETDB_INTERNAL;
@ -155,11 +159,6 @@ enum nss_status
_nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer, _nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer,
size_t buflen, int *errnop, int *herrnop) size_t buflen, int *errnop, int *herrnop)
{ {
enum nss_status retval;
struct parser_data *data = (void *) buffer;
char *domain, *result, *p;
int len, parse_res;
if (name == NULL) if (name == NULL)
{ {
*errnop = EINVAL; *errnop = EINVAL;
@ -167,33 +166,36 @@ _nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer,
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
} }
if (yp_get_default_domain (&domain)) char *domain;
if (__builtin_expect (yp_get_default_domain (&domain), 0))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
struct parser_data *data = (void *) buffer;
if (buflen < sizeof *data + 1) if (buflen < sizeof *data + 1)
{ {
*herrnop = NETDB_INTERNAL; *herrnop = NETDB_INTERNAL;
*errnop = ERANGE; *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
else
/* Convert name to lowercase. */
size_t namlen = strlen (name);
char name2[namlen + 1];
size_t i;
for (i = 0; i < namlen; ++i)
name2[i] = _tolower (name[i]);
name2[i] = '\0';
char *result;
int len;
int yperr = yp_match (domain, "networks.byname", name2, namlen, &result,
&len);
if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
/* Convert name to lowercase. */ enum nss_status retval = yperr2nss (yperr);
size_t namlen = strlen (name);
char name2[namlen + 1];
size_t i;
for (i = 0; i < namlen; ++i)
name2[i] = _tolower (name[i]);
name2[i] = '\0';
retval = yperr2nss (yp_match (domain, "networks.byname", name2,
namlen, &result, &len));
}
if (retval != NSS_STATUS_SUCCESS)
{
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
{ {
*errnop = errno; *errnop = errno;
@ -202,7 +204,7 @@ _nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer,
return retval; return retval;
} }
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
@ -210,15 +212,15 @@ _nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer,
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_netent (p, net, data, buflen, errnop); int parse_res = _nss_files_parse_netent (p, net, data, buflen, errnop);
if (parse_res < 1) if (__builtin_expect (parse_res < 1, 0))
{ {
*herrnop = NETDB_INTERNAL; *herrnop = NETDB_INTERNAL;
if (parse_res == -1) if (parse_res == -1)
@ -235,32 +237,26 @@ _nss_nis_getnetbyaddr_r (uint32_t addr, int type, struct netent *net,
char *buffer, size_t buflen, int *errnop, char *buffer, size_t buflen, int *errnop,
int *herrnop) int *herrnop)
{ {
struct parser_data *data = (void *) buffer;
char *domain; char *domain;
char *result; if (__builtin_expect (yp_get_default_domain (&domain), 0))
int len;
char buf[256];
int blen;
struct in_addr in;
char *p;
if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
in = inet_makeaddr (addr, 0); struct in_addr in = inet_makeaddr (addr, 0);
strcpy (buf, inet_ntoa (in)); char *buf = inet_ntoa (in);
blen = strlen (buf); size_t blen = strlen (buf);
while (1) while (1)
{ {
enum nss_status retval; char *result;
int parse_res; int len;
retval = yperr2nss (yp_match (domain, "networks.byaddr", buf, int yperr = yp_match (domain, "networks.byaddr", buf, blen, &result,
strlen (buf), &result, &len)); &len);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_NOTFOUND) if (retval == NSS_STATUS_NOTFOUND)
{ {
if (buf[blen - 2] == '.' && buf[blen - 1] == '0') if (buf[blen - 2] == '.' && buf[blen - 1] == '0')
@ -282,7 +278,7 @@ _nss_nis_getnetbyaddr_r (uint32_t addr, int type, struct netent *net,
} }
} }
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
@ -290,15 +286,16 @@ _nss_nis_getnetbyaddr_r (uint32_t addr, int type, struct netent *net,
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_netent (p, net, data, buflen, errnop); int parse_res = _nss_files_parse_netent (p, net, (void *) buffer,
buflen, errnop);
if (parse_res < 1) if (__builtin_expect (parse_res < 1, 0))
{ {
*herrnop = NETDB_INTERNAL; *herrnop = NETDB_INTERNAL;
if (parse_res == -1) if (parse_res == -1)

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1996-1998, 2000-2003, 2004 Free Software Foundation, Inc. /* Copyright (C) 1996-1998, 2000-2004, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@ -179,45 +179,46 @@ enum nss_status
_nss_nis_getprotobyname_r (const char *name, struct protoent *proto, _nss_nis_getprotobyname_r (const char *name, struct protoent *proto,
char *buffer, size_t buflen, int *errnop) char *buffer, size_t buflen, int *errnop)
{ {
struct parser_data *data = (void *) buffer;
enum nss_status retval;
char *domain, *result, *p;
int len, parse_res;
if (name == NULL) if (name == NULL)
{ {
*errnop = EINVAL; *errnop = EINVAL;
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
} }
if (yp_get_default_domain (&domain)) char *domain;
if (__builtin_expect (yp_get_default_domain (&domain), 0))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
retval = yperr2nss (yp_match (domain, "protocols.byname", name, char *result;
strlen (name), &result, &len)); int len;
int yperr = yp_match (domain, "protocols.byname", name, strlen (name),
&result, &len);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
} }
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_protoent (p, proto, data, buflen, errnop); int parse_res = _nss_files_parse_protoent (p, proto, (void *) buffer, buflen,
if (parse_res < 1) errnop);
if (__builtin_expect (parse_res < 1, 0))
{ {
if (parse_res == -1) if (parse_res == -1)
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
@ -231,42 +232,43 @@ enum nss_status
_nss_nis_getprotobynumber_r (int number, struct protoent *proto, _nss_nis_getprotobynumber_r (int number, struct protoent *proto,
char *buffer, size_t buflen, int *errnop) char *buffer, size_t buflen, int *errnop)
{ {
struct parser_data *data = (void *) buffer; char *domain;
enum nss_status retval; if (__builtin_expect (yp_get_default_domain (&domain), 0))
char *domain, *result, *p;
int len, nlen, parse_res;
char buf[32];
if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
nlen = sprintf (buf, "%d", number); char buf[32];
int nlen = snprintf (buf, sizeof (buf), "%d", number);
retval = yperr2nss (yp_match (domain, "protocols.bynumber", buf, char *result;
nlen, &result, &len)); int len;
int yperr = yp_match (domain, "protocols.bynumber", buf, nlen, &result,
&len);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
} }
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_protoent (p, proto, data, buflen, errnop); int parse_res = _nss_files_parse_protoent (p, proto, (void *) buffer, buflen,
if (parse_res < 1) errnop);
if (__builtin_expect (parse_res < 1, 0))
{ {
if (parse_res == -1) if (parse_res == -1)
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;

View File

@ -36,10 +36,6 @@ extern int xdecrypt (char *, char *);
enum nss_status enum nss_status
_nss_nis_getpublickey (const char *netname, char *pkey, int *errnop) _nss_nis_getpublickey (const char *netname, char *pkey, int *errnop)
{ {
enum nss_status retval;
char *domain, *result;
int len;
pkey[0] = 0; pkey[0] = 0;
if (netname == NULL) if (netname == NULL)
@ -48,19 +44,23 @@ _nss_nis_getpublickey (const char *netname, char *pkey, int *errnop)
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
} }
domain = strchr (netname, '@'); char *domain = strchr (netname, '@');
if (!domain) if (domain == NULL)
{ {
*errnop = EINVAL; *errnop = EINVAL;
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
} }
++domain; ++domain;
retval = yperr2nss (yp_match (domain, "publickey.byname", netname, char *result;
strlen (netname), &result, &len)); int len;
int yperr = yp_match (domain, "publickey.byname", netname, strlen (netname),
&result, &len);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
@ -82,11 +82,6 @@ enum nss_status
_nss_nis_getsecretkey (const char *netname, char *skey, char *passwd, _nss_nis_getsecretkey (const char *netname, char *skey, char *passwd,
int *errnop) int *errnop)
{ {
enum nss_status retval;
char buf[2 * (HEXKEYBYTES + 1)];
char *domain, *result;
int len;
skey[0] = 0; skey[0] = 0;
if (netname == NULL || passwd == NULL) if (netname == NULL || passwd == NULL)
@ -95,19 +90,23 @@ _nss_nis_getsecretkey (const char *netname, char *skey, char *passwd,
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
} }
domain = strchr (netname, '@'); char *domain = strchr (netname, '@');
if (!domain) if (domain == NULL)
{ {
*errnop = EINVAL; *errnop = EINVAL;
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
} }
++domain; ++domain;
retval = yperr2nss (yp_match (domain, "publickey.byname", netname, char *result;
strlen (netname), &result, &len)); int len;
int yperr = yp_match (domain, "publickey.byname", netname, strlen (netname),
&result, &len);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
@ -118,6 +117,8 @@ _nss_nis_getsecretkey (const char *netname, char *skey, char *passwd,
char *p = strchr (result, ':'); char *p = strchr (result, ':');
if (p != NULL) if (p != NULL)
{ {
char buf[2 * (HEXKEYBYTES + 1)];
++p; ++p;
strncpy (buf, p, 2 * (HEXKEYBYTES + 1)); strncpy (buf, p, 2 * (HEXKEYBYTES + 1));
buf[2 * HEXKEYBYTES + 1] = '\0'; buf[2 * HEXKEYBYTES + 1] = '\0';
@ -195,13 +196,8 @@ enum nss_status
_nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp, _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
gid_t *gidp, int *gidlenp, gid_t *gidlist, int *errnop) gid_t *gidp, int *gidlenp, gid_t *gidlist, int *errnop)
{ {
char *domain; char *domain = strchr (netname, '@');
int yperr; if (domain == NULL)
char *lookup;
int len;
domain = strchr (netname, '@');
if (!domain)
{ {
*errnop = EINVAL; *errnop = EINVAL;
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
@ -209,9 +205,10 @@ _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
/* Point past the '@' character */ /* Point past the '@' character */
++domain; ++domain;
lookup = NULL; char *lookup = NULL;
yperr = yp_match (domain, "netid.byname", netname, strlen (netname), int len;
&lookup, &len); int yperr = yp_match (domain, "netid.byname", netname, strlen (netname),
&lookup, &len);
switch (yperr) switch (yperr)
{ {
case YPERR_SUCCESS: case YPERR_SUCCESS:
@ -224,17 +221,15 @@ _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
} }
if (lookup) if (lookup == NULL)
{
enum nss_status err;
lookup[len] = '\0';
err = parse_netid_str (lookup, uidp, gidp, gidlenp, gidlist);
free (lookup);
return err;
}
else
return NSS_STATUS_NOTFOUND; return NSS_STATUS_NOTFOUND;
return NSS_STATUS_SUCCESS;
lookup[len] = '\0';
enum nss_status err = parse_netid_str (lookup, uidp, gidp, gidlenp, gidlist);
free (lookup);
return err;
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1996-1998, 2001, 2002, 2003 Free Software Foundation, Inc. /* Copyright (C) 1996-1998,2001,2002,2003,2006 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996. Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
@ -71,31 +71,31 @@ static enum nss_status
internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen, internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
int *errnop) int *errnop)
{ {
struct parser_data *data = (void *) buffer;
char *domain; char *domain;
int parse_res; if (__builtin_expect (yp_get_default_domain (&domain), 0))
if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
/* Get the next entry until we found a correct one. */ /* Get the next entry until we found a correct one. */
int parse_res;
do do
{ {
enum nss_status retval; char *result;
char *result, *outkey, *result2, *p; char *outkey;
int len, keylen, len2; int len;
size_t namelen; int keylen;
int yperr;
if (new_start) if (new_start)
retval = yperr2nss (yp_first (domain, "passwd.byname", yperr = yp_first (domain, "passwd.byname", &outkey, &keylen, &result,
&outkey, &keylen, &result, &len)); &len);
else else
retval = yperr2nss ( yp_next (domain, "passwd.byname", yperr = yp_next (domain, "passwd.byname", oldkey, oldkeylen, &outkey,
oldkey, oldkeylen, &keylen, &result, &len);
&outkey, &keylen, &result, &len));
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
@ -103,7 +103,10 @@ internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
/* Check for adjunct style secret passwords. They can be /* Check for adjunct style secret passwords. They can be
recognized by a password starting with "##". */ recognized by a password starting with "##". */
p = strchr (result, ':'); char *p = strchr (result, ':');
size_t namelen;
char *result2;
int len2;
if (p != NULL /* This better should be true in all cases. */ if (p != NULL /* This better should be true in all cases. */
&& p[1] == '#' && p[2] == '#' && p[1] == '#' && p[2] == '#'
&& (namelen = p - result, && (namelen = p - result,
@ -128,7 +131,8 @@ internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
} }
restlen = len - (p - result); restlen = len - (p - result);
if ((size_t) (namelen + (endp - encrypted) + restlen + 2) > buflen) if (__builtin_expect ((size_t) (namelen + (endp - encrypted)
+ restlen + 2) > buflen, 0))
{ {
free (result2); free (result2);
free (result); free (result);
@ -147,7 +151,7 @@ internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
else else
{ {
non_adjunct: non_adjunct:
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
@ -162,8 +166,9 @@ internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_pwent (p, pwd, data, buflen, errnop); parse_res = _nss_files_parse_pwent (p, pwd, (void *) buffer, buflen,
if (parse_res == -1) errnop);
if (__builtin_expect (parse_res == -1, 0))
{ {
free (outkey); free (outkey);
*errnop = ERANGE; *errnop = ERANGE;
@ -199,28 +204,26 @@ enum nss_status
_nss_nis_getpwnam_r (const char *name, struct passwd *pwd, _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
char *buffer, size_t buflen, int *errnop) char *buffer, size_t buflen, int *errnop)
{ {
struct parser_data *data = (void *) buffer;
enum nss_status retval;
char *domain, *result, *result2, *p;
int len, len2, parse_res;
size_t namelen;
if (name == NULL) if (name == NULL)
{ {
*errnop = EINVAL; *errnop = EINVAL;
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
} }
if (yp_get_default_domain (&domain)) char *domain;
if (__builtin_expect (yp_get_default_domain (&domain), 0))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
namelen = strlen (name); size_t namelen = strlen (name);
retval = yperr2nss (yp_match (domain, "passwd.byname", name, char *result;
namelen, &result, &len)); int len;
int yperr = yp_match (domain, "passwd.byname", name, namelen, &result, &len);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
@ -228,7 +231,9 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
/* Check for adjunct style secret passwords. They can be recognized /* Check for adjunct style secret passwords. They can be recognized
by a password starting with "##". */ by a password starting with "##". */
p = strchr (result, ':'); char *result2;
int len2;
char *p = strchr (result, ':');
if (p != NULL /* This better should be true in all cases. */ if (p != NULL /* This better should be true in all cases. */
&& p[1] == '#' && p[2] == '#' && p[1] == '#' && p[2] == '#'
&& yp_match (domain, "passwd.adjunct.byname", name, namelen, && yp_match (domain, "passwd.adjunct.byname", name, namelen,
@ -238,7 +243,6 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
therein into original result. */ therein into original result. */
char *encrypted = strchr (result2, ':'); char *encrypted = strchr (result2, ':');
char *endp; char *endp;
size_t restlen;
if (encrypted == NULL if (encrypted == NULL
|| (endp = strchr (++encrypted, ':')) == NULL || (endp = strchr (++encrypted, ':')) == NULL
@ -251,8 +255,9 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
goto non_adjunct; goto non_adjunct;
} }
restlen = len - (p - result); size_t restlen = len - (p - result);
if ((size_t) (namelen + (endp - encrypted) + restlen + 2) > buflen) if (__builtin_expect ((size_t) (namelen + (endp - encrypted)
+ restlen + 2) > buflen, 0))
{ {
free (result2); free (result2);
free (result); free (result);
@ -271,7 +276,7 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
else else
{ {
non_adjunct: non_adjunct:
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
@ -286,8 +291,9 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_pwent (p, pwd, data, buflen, errnop); int parse_res = _nss_files_parse_pwent (p, pwd, (void *) buffer, buflen,
if (parse_res < 1) errnop);
if (__builtin_expect (parse_res < 1, 0))
{ {
if (parse_res == -1) if (parse_res == -1)
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
@ -302,23 +308,21 @@ enum nss_status
_nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd, _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
char *buffer, size_t buflen, int *errnop) char *buffer, size_t buflen, int *errnop)
{ {
struct parser_data *data = (void *) buffer; char *domain;
enum nss_status retval; if (__builtin_expect (yp_get_default_domain (&domain), 0))
char *domain, *result, *p, *result2;
int len, nlen, parse_res, len2;
char buf[32];
size_t namelen;
if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
nlen = sprintf (buf, "%lu", (unsigned long int) uid); char buf[32];
int nlen = snprintf (buf, sizeof (buf), "%lu", (unsigned long int) uid);
retval = yperr2nss (yp_match (domain, "passwd.byuid", buf, char *result;
nlen, &result, &len)); int len;
int yperr = yp_match (domain, "passwd.byuid", buf, nlen, &result, &len);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
@ -326,7 +330,10 @@ _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
/* Check for adjunct style secret passwords. They can be recognized /* Check for adjunct style secret passwords. They can be recognized
by a password starting with "##". */ by a password starting with "##". */
p = strchr (result, ':'); char *result2;
int len2;
size_t namelen;
char *p = strchr (result, ':');
if (p != NULL /* This better should be true in all cases. */ if (p != NULL /* This better should be true in all cases. */
&& p[1] == '#' && p[2] == '#' && p[1] == '#' && p[2] == '#'
&& (namelen = p - result, && (namelen = p - result,
@ -351,7 +358,8 @@ _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
} }
restlen = len - (p - result); restlen = len - (p - result);
if ((size_t) (namelen + (endp - encrypted) + restlen + 2) > buflen) if (__builtin_expect ((size_t) (namelen + (endp - encrypted)
+ restlen + 2) > buflen, 0))
{ {
free (result2); free (result2);
free (result); free (result);
@ -370,7 +378,7 @@ _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
else else
{ {
non_adjunct: non_adjunct:
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
@ -385,8 +393,9 @@ _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_pwent (p, pwd, data, buflen, errnop); int parse_res = _nss_files_parse_pwent (p, pwd, (void *) buffer, buflen,
if (parse_res < 1) errnop);
if (__builtin_expect (parse_res < 1, 0))
{ {
if (parse_res == -1) if (parse_res == -1)
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;

View File

@ -1,4 +1,5 @@
/* Copyright (C) 1996-1998,2000,2002,2003,2004 Free Software Foundation, Inc. /* Copyright (C) 1996-1998,2000,2002,2003,2004,2006
Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@ -54,7 +55,7 @@ static int
saveit (int instatus, char *inkey, int inkeylen, char *inval, saveit (int instatus, char *inkey, int inkeylen, char *inval,
int invallen, char *indata) int invallen, char *indata)
{ {
intern_t *intern = (intern_t *)indata; intern_t *intern = (intern_t *) indata;
if (instatus != YP_TRUE) if (instatus != YP_TRUE)
return 1; return 1;
@ -158,7 +159,7 @@ internal_nis_getrpcent_r (struct rpcent *rpc, char *buffer, size_t buflen,
++p; ++p;
parse_res = _nss_files_parse_rpcent (p, rpc, pdata, buflen, errnop); parse_res = _nss_files_parse_rpcent (p, rpc, pdata, buflen, errnop);
if (parse_res == -1) if (__builtin_expect (parse_res == -1, 0))
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
data->next = data->next->next; data->next = data->next->next;
} }
@ -186,21 +187,18 @@ enum nss_status
_nss_nis_getrpcbyname_r (const char *name, struct rpcent *rpc, _nss_nis_getrpcbyname_r (const char *name, struct rpcent *rpc,
char *buffer, size_t buflen, int *errnop) char *buffer, size_t buflen, int *errnop)
{ {
intern_t data = {NULL, NULL};
enum nss_status status;
int found;
if (name == NULL) if (name == NULL)
{ {
*errnop = EINVAL; *errnop = EINVAL;
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
} }
status = internal_nis_setrpcent (&data); intern_t data = { NULL, NULL };
if (status != NSS_STATUS_SUCCESS) enum nss_status status = internal_nis_setrpcent (&data);
if (__builtin_expect (status != NSS_STATUS_SUCCESS, 0))
return status; return status;
found = 0; int found = 0;
while (!found && while (!found &&
((status = internal_nis_getrpcent_r (rpc, buffer, buflen, errnop, ((status = internal_nis_getrpcent_r (rpc, buffer, buflen, errnop,
&data)) == NSS_STATUS_SUCCESS)) &data)) == NSS_STATUS_SUCCESS))
@ -226,53 +224,52 @@ _nss_nis_getrpcbyname_r (const char *name, struct rpcent *rpc,
internal_nis_endrpcent (&data); internal_nis_endrpcent (&data);
if (!found && status == NSS_STATUS_SUCCESS) if (__builtin_expect (!found && status == NSS_STATUS_SUCCESS, 0))
return NSS_STATUS_NOTFOUND; return NSS_STATUS_NOTFOUND;
else
return status; return status;
} }
enum nss_status enum nss_status
_nss_nis_getrpcbynumber_r (int number, struct rpcent *rpc, _nss_nis_getrpcbynumber_r (int number, struct rpcent *rpc,
char *buffer, size_t buflen, int *errnop) char *buffer, size_t buflen, int *errnop)
{ {
struct parser_data *data = (void *) buffer; char *domain;
enum nss_status retval; if (__builtin_expect (yp_get_default_domain (&domain), 0))
char *domain, *result, *p;
int len, nlen, parse_res;
char buf[32];
if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
nlen = sprintf (buf, "%d", number); char buf[32];
int nlen = snprintf (buf, sizeof (buf), "%d", number);
retval = yperr2nss (yp_match (domain, "rpc.bynumber", buf, char *result;
nlen, &result, &len)); int len;
int yperr = yp_match (domain, "rpc.bynumber", buf, nlen, &result, &len);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
} }
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_rpcent (p, rpc, data, buflen, errnop); int parse_res = _nss_files_parse_rpcent (p, rpc, (void *) buffer, buflen,
errnop);
if (parse_res < 1) if (__builtin_expect (parse_res < 1, 0))
{ {
if (parse_res == -1) if (parse_res == -1)
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1996-2001, 2002, 2003, 2004 Free Software Foundation, Inc. /* Copyright (C) 1996-2004, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@ -98,29 +98,26 @@ dosearch (int instatus, char *inkey, int inkeylen, char *inval,
{ {
struct search_t *req = (struct search_t *) indata; struct search_t *req = (struct search_t *) indata;
if (instatus != YP_TRUE) if (__builtin_expect (instatus != YP_TRUE, 0))
return 1; return 1;
if (inkey && inkeylen > 0 && inval && invallen > 0) if (inkey && inkeylen > 0 && inval && invallen > 0)
{ {
struct parser_data *pdata = (void *) req->buffer; if (__builtin_expect ((size_t) (invallen + 1) > req->buflen, 0))
int parse_res;
char *p;
if ((size_t) (invallen + 1) > req->buflen)
{ {
*req->errnop = ERANGE; *req->errnop = ERANGE;
req->status = NSS_STATUS_TRYAGAIN; req->status = NSS_STATUS_TRYAGAIN;
return 1; return 1;
} }
p = strncpy (req->buffer, inval, invallen); char *p = strncpy (req->buffer, inval, invallen);
req->buffer[invallen] = '\0'; req->buffer[invallen] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
parse_res = _nss_files_parse_servent (p, req->serv, pdata, req->buflen, int parse_res = _nss_files_parse_servent (p, req->serv,
req->errnop); (void *) req->buffer,
req->buflen, req->errnop);
if (parse_res == -1) if (parse_res == -1)
{ {
req->status = NSS_STATUS_TRYAGAIN; req->status = NSS_STATUS_TRYAGAIN;
@ -237,7 +234,7 @@ internal_nis_getservent_r (struct servent *serv, char *buffer,
++p; ++p;
parse_res = _nss_files_parse_servent (p, serv, pdata, buflen, errnop); parse_res = _nss_files_parse_servent (p, serv, pdata, buflen, errnop);
if (parse_res == -1) if (__builtin_expect (parse_res == -1, 0))
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
data->next = data->next->next; data->next = data->next->next;
} }
@ -266,60 +263,56 @@ _nss_nis_getservbyname_r (const char *name, const char *protocol,
struct servent *serv, char *buffer, size_t buflen, struct servent *serv, char *buffer, size_t buflen,
int *errnop) int *errnop)
{ {
enum nss_status status;
char *domain;
if (name == NULL) if (name == NULL)
{ {
*errnop = EINVAL; *errnop = EINVAL;
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
} }
if (yp_get_default_domain (&domain)) char *domain;
if (__builtin_expect (yp_get_default_domain (&domain), 0))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
/* If the protocol is given, we could try if our NIS server knows /* If the protocol is given, we could try if our NIS server knows
about services.byservicename map. If yes, we only need one query. */ about services.byservicename map. If yes, we only need one query. */
char key[strlen (name) + (protocol ? strlen (protocol) : 0) + 2]; size_t keylen = strlen (name) + 1 + (protocol ? strlen (protocol) : 0);
char *cp, *result; char key[keylen + 1];
size_t keylen, len;
int int_len;
/* key is: "name/proto" */ /* key is: "name/proto" */
cp = stpcpy (key, name); char *cp = stpcpy (key, name);
if (protocol) if (protocol != NULL)
{ {
*cp++ = '/'; *cp++ = '/';
strcpy (cp, protocol); strcpy (cp, protocol);
} }
keylen = strlen (key);
status = yperr2nss (yp_match (domain, "services.byservicename", key, char *result;
keylen, &result, &int_len)); int int_len;
len = int_len; enum nss_status status = yperr2nss (yp_match (domain,
"services.byservicename", key,
keylen, &result, &int_len));
size_t len = int_len;
/* If we found the key, it's ok and parse the result. If not, /* If we found the key, it's ok and parse the result. If not,
fall through and parse the complete table. */ fall through and parse the complete table. */
if (status == NSS_STATUS_SUCCESS) if (__builtin_expect (status == NSS_STATUS_SUCCESS, 1))
{ {
struct parser_data *pdata = (void *) buffer; if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
int parse_res;
char *p;
if ((size_t) (len + 1) > buflen)
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_servent (p, serv, pdata,
buflen, errnop); int parse_res = _nss_files_parse_servent (p, serv, (void *) buffer,
if (parse_res < 0) buflen, errnop);
if (__builtin_expect (parse_res < 0, 0))
{ {
if (parse_res == -1) if (parse_res == -1)
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
@ -360,10 +353,8 @@ _nss_nis_getservbyport_r (int port, const char *protocol,
struct servent *serv, char *buffer, struct servent *serv, char *buffer,
size_t buflen, int *errnop) size_t buflen, int *errnop)
{ {
enum nss_status status;
char *domain; char *domain;
if (__builtin_expect (yp_get_default_domain (&domain), 0))
if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
/* If the protocol is given, we only need one query. /* If the protocol is given, we only need one query.
@ -372,48 +363,45 @@ _nss_nis_getservbyport_r (int port, const char *protocol,
const char *proto = protocol != NULL ? protocol : "tcp"; const char *proto = protocol != NULL ? protocol : "tcp";
do do
{ {
char key[sizeof (int) * 3 + strlen (proto) + 2];
char *result;
size_t keylen, len;
int int_len;
/* key is: "port/proto" */ /* key is: "port/proto" */
keylen = snprintf (key, sizeof (key), "%d/%s", ntohs (port), proto); char key[sizeof (int) * 3 + strlen (proto) + 2];
status = yperr2nss (yp_match (domain, "services.byname", key, size_t keylen = snprintf (key, sizeof (key), "%d/%s", ntohs (port),
keylen, &result, &int_len)); proto);
len = int_len;
char *result;
int int_len;
enum nss_status status = yperr2nss (yp_match (domain, "services.byname",
key, keylen, &result,
&int_len));
size_t len = int_len;
/* If we found the key, it's ok and parse the result. If not, /* If we found the key, it's ok and parse the result. If not,
fall through and parse the complete table. */ fall through and parse the complete table. */
if (status == NSS_STATUS_SUCCESS) if (status == NSS_STATUS_SUCCESS)
{ {
struct parser_data *pdata = (void *) buffer; if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
int parse_res;
char *p;
if ((size_t) (len + 1) > buflen)
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_servent (p, serv, pdata, int parse_res = _nss_files_parse_servent (p, serv, (void *) buffer,
buflen, errnop); buflen, errnop);
if (parse_res < 0) if (__builtin_expect (parse_res < 0, 0))
{ {
if (parse_res == -1) if (parse_res == -1)
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
else else
return NSS_STATUS_NOTFOUND; return NSS_STATUS_NOTFOUND;
} }
else
return NSS_STATUS_SUCCESS; return NSS_STATUS_SUCCESS;
} }
} }
while (protocol == NULL && (proto[0] == 't' ? (proto = "udp") : NULL)); while (protocol == NULL && (proto[0] == 't' ? (proto = "udp") : NULL));
@ -434,7 +422,8 @@ _nss_nis_getservbyport_r (int port, const char *protocol,
req.buflen = buflen; req.buflen = buflen;
req.errnop = errnop; req.errnop = errnop;
req.status = NSS_STATUS_NOTFOUND; req.status = NSS_STATUS_NOTFOUND;
status = yperr2nss (yp_all (domain, "services.byname", &ypcb)); enum nss_status status = yperr2nss (yp_all (domain, "services.byname",
&ypcb));
if (status != NSS_STATUS_SUCCESS) if (status != NSS_STATUS_SUCCESS)
return status; return status;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1996-1998, 2001, 2002, 2003 Free Software Foundation, Inc. /* Copyright (C) 1996-1998,2001,2002,2003,2006 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996. Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
@ -69,48 +69,53 @@ internal_nis_getspent_r (struct spwd *sp, char *buffer, size_t buflen,
int *errnop) int *errnop)
{ {
struct parser_data *data = (void *) buffer; struct parser_data *data = (void *) buffer;
char *domain, *result, *outkey;
int len, keylen, parse_res;
if (yp_get_default_domain (&domain)) char *domain;
if (__builtin_expect (yp_get_default_domain (&domain), 0))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
/* Get the next entry until we found a correct one. */ /* Get the next entry until we found a correct one. */
int parse_res;
do do
{ {
enum nss_status retval; char *result;
char *p; char *outkey;
int len;
int keylen;
int yperr;
if (new_start) if (new_start)
retval = yperr2nss (yp_first (domain, "shadow.byname", yperr = yp_first (domain, "shadow.byname", &outkey, &keylen, &result,
&outkey, &keylen, &result, &len)); &len);
else else
retval = yperr2nss ( yp_next (domain, "shadow.byname", yperr = yp_next (domain, "shadow.byname", oldkey, oldkeylen, &outkey,
oldkey, oldkeylen, &keylen, &result, &len);
&outkey, &keylen, &result, &len));
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
} }
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_spent (p, sp, data, buflen, errnop); parse_res = _nss_files_parse_spent (p, sp, (void *) buffer, buflen,
if (parse_res == -1) errnop);
if (__builtin_expect (parse_res == -1, 0))
{ {
free (outkey); free (outkey);
*errnop = ERANGE; *errnop = ERANGE;
@ -146,45 +151,46 @@ enum nss_status
_nss_nis_getspnam_r (const char *name, struct spwd *sp, _nss_nis_getspnam_r (const char *name, struct spwd *sp,
char *buffer, size_t buflen, int *errnop) char *buffer, size_t buflen, int *errnop)
{ {
struct parser_data *data = (void *) buffer;
enum nss_status retval;
char *domain, *result, *p;
int len, parse_res;
if (name == NULL) if (name == NULL)
{ {
*errnop = EINVAL; *errnop = EINVAL;
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
} }
if (yp_get_default_domain (&domain)) char *domain;
if (__builtin_expect (yp_get_default_domain (&domain), 0))
return NSS_STATUS_UNAVAIL; return NSS_STATUS_UNAVAIL;
retval = yperr2nss (yp_match (domain, "shadow.byname", name, char *result;
strlen (name), &result, &len)); int len;
int yperr = yp_match (domain, "shadow.byname", name, strlen (name), &result,
&len);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{ {
enum nss_status retval = yperr2nss (yperr);
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno; *errnop = errno;
return retval; return retval;
} }
if ((size_t) (len + 1) > buflen) if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{ {
free (result); free (result);
*errnop = ERANGE; *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
p = strncpy (buffer, result, len); char *p = strncpy (buffer, result, len);
buffer[len] = '\0'; buffer[len] = '\0';
while (isspace (*p)) while (isspace (*p))
++p; ++p;
free (result); free (result);
parse_res = _nss_files_parse_spent (p, sp, data, buflen, errnop); int parse_res = _nss_files_parse_spent (p, sp, (void *) buffer, buflen,
if (parse_res < 1) errnop);
if (__builtin_expect (parse_res < 1, 0))
{ {
if (parse_res == -1) if (parse_res == -1)
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;

View File

@ -1,5 +1,14 @@
2006-04-08 Ulrich Drepper <drepper@redhat.com> 2006-04-08 Ulrich Drepper <drepper@redhat.com>
* sysdeps/unix/sysv/linux/i386/lowlevellock.h: Remove branch predicion
suffix for conditional jumps.
* sysdeps/unix/sysv/linux/i386/i486/sem_trywait.S: Likewise.
* sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S: Likewise.
* sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S: Likewise.
* sysdeps/unix/sysv/linux/i386/i486/pthread_barrier_wait.S: Likewise.
* sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S: Likewise.
* sysdeps/unix/sysv/linux/i386/i486/sem_wait.S: Likewise.
* init.c (sigcancel_handler): Compare with correct PID even if the * init.c (sigcancel_handler): Compare with correct PID even if the
thread is in the middle of a fork call. thread is in the middle of a fork call.
(sighandler_setxid): Likewise. (sighandler_setxid): Likewise.

View File

@ -22,7 +22,7 @@
#ifndef UP #ifndef UP
# define LOCK \ # define LOCK \
cmpl $0, %gs:MULTIPLE_THREADS_OFFSET; \ cmpl $0, %gs:MULTIPLE_THREADS_OFFSET; \
je,pt 0f; \ je 0f; \
lock; \ lock; \
0: 0:
#endif #endif

View File

@ -60,7 +60,7 @@ __lll_mutex_lock_wait:
xchgl %eax, (%ebx) /* NB: lock is implied */ xchgl %eax, (%ebx) /* NB: lock is implied */
testl %eax, %eax testl %eax, %eax
jnz,pn 1b jnz 1b
popl %esi popl %esi
popl %ebx popl %ebx

View File

@ -82,7 +82,7 @@ pthread_barrier_wait:
#else #else
cmpl %edx, CURR_EVENT(%ebx) cmpl %edx, CURR_EVENT(%ebx)
#endif #endif
je,pn 8b je 8b
/* Increment LEFT. If this brings the count back to the /* Increment LEFT. If this brings the count back to the
initial count unlock the object. */ initial count unlock the object. */
@ -92,7 +92,7 @@ pthread_barrier_wait:
xaddl %edx, LEFT(%ebx) xaddl %edx, LEFT(%ebx)
subl $1, %ecx subl $1, %ecx
cmpl %ecx, %edx cmpl %ecx, %edx
jne,pt 10f jne 10f
/* Release the mutex. We cannot release the lock before /* Release the mutex. We cannot release the lock before
waking the waiting threads since otherwise a new thread might waking the waiting threads since otherwise a new thread might
@ -131,7 +131,7 @@ pthread_barrier_wait:
xaddl %edx, LEFT(%ebx) xaddl %edx, LEFT(%ebx)
subl $1, %ecx subl $1, %ecx
cmpl %ecx, %edx cmpl %ecx, %edx
jne,pt 5f jne 5f
/* Release the mutex. We cannot release the lock before /* Release the mutex. We cannot release the lock before
waking the waiting threads since otherwise a new thread might waking the waiting threads since otherwise a new thread might

View File

@ -49,12 +49,12 @@ sem_timedwait:
movl (%ecx), %eax movl (%ecx), %eax
2: testl %eax, %eax 2: testl %eax, %eax
je,pn 1f je 1f
leal -1(%eax), %edx leal -1(%eax), %edx
LOCK LOCK
cmpxchgl %edx, (%ecx) cmpxchgl %edx, (%ecx)
jne,pn 2b jne 2b
xorl %eax, %eax xorl %eax, %eax
ret ret
@ -117,7 +117,7 @@ sem_timedwait:
call __pthread_disable_asynccancel call __pthread_disable_asynccancel
testl %esi, %esi testl %esi, %esi
je,pt 9f je 9f
cmpl $-EWOULDBLOCK, %esi cmpl $-EWOULDBLOCK, %esi
jne 3f jne 3f
@ -128,7 +128,7 @@ sem_timedwait:
leal -1(%eax), %ecx leal -1(%eax), %ecx
LOCK LOCK
cmpxchgl %ecx, (%ebx) cmpxchgl %ecx, (%ebx)
jne,pn 8b jne 8b
addl $12, %esp addl $12, %esp
cfi_adjust_cfa_offset(-12) cfi_adjust_cfa_offset(-12)

View File

@ -42,7 +42,7 @@ __new_sem_trywait:
leal -1(%eax), %edx leal -1(%eax), %edx
LOCK LOCK
cmpxchgl %edx, (%ecx) cmpxchgl %edx, (%ecx)
jne,pn 2b jne 2b
xorl %eax, %eax xorl %eax, %eax
ret ret

View File

@ -62,7 +62,7 @@ __new_sem_wait:
leal -1(%eax), %edx leal -1(%eax), %edx
LOCK LOCK
cmpxchgl %edx, (%ebx) cmpxchgl %edx, (%ebx)
jne,pn 2b jne 2b
xorl %eax, %eax xorl %eax, %eax
movl 4(%esp), %esi movl 4(%esp), %esi

View File

@ -384,7 +384,7 @@ extern int lll_unlock_wake_cb (int *__futex) attribute_hidden;
# define lll_trylock(futex) \ # define lll_trylock(futex) \
({ unsigned char ret; \ ({ unsigned char ret; \
__asm __volatile ("cmpl $0, %%gs:%P5\n\t" \ __asm __volatile ("cmpl $0, %%gs:%P5\n\t" \
"je,pt 0f\n\t" \ "je 0f\n\t" \
"lock\n" \ "lock\n" \
"0:\tcmpxchgl %2, %1; setne %0" \ "0:\tcmpxchgl %2, %1; setne %0" \
: "=a" (ret), "=m" (futex) \ : "=a" (ret), "=m" (futex) \
@ -398,7 +398,7 @@ extern int lll_unlock_wake_cb (int *__futex) attribute_hidden;
# define lll_lock(futex) \ # define lll_lock(futex) \
(void) ({ int ignore1, ignore2; \ (void) ({ int ignore1, ignore2; \
__asm __volatile ("cmpl $0, %%gs:%P6\n\t" \ __asm __volatile ("cmpl $0, %%gs:%P6\n\t" \
"je,pt 0f\n\t" \ "je 0f\n\t" \
"lock\n" \ "lock\n" \
"0:\tcmpxchgl %1, %2\n\t" \ "0:\tcmpxchgl %1, %2\n\t" \
"jnz _L_mutex_lock_%=\n\t" \ "jnz _L_mutex_lock_%=\n\t" \
@ -420,7 +420,7 @@ extern int lll_unlock_wake_cb (int *__futex) attribute_hidden;
# define lll_unlock(futex) \ # define lll_unlock(futex) \
(void) ({ int ignore; \ (void) ({ int ignore; \
__asm __volatile ("cmpl $0, %%gs:%P3\n\t" \ __asm __volatile ("cmpl $0, %%gs:%P3\n\t" \
"je,pt 0f\n\t" \ "je 0f\n\t" \
"lock\n" \ "lock\n" \
"0:\tsubl $1,%0\n\t" \ "0:\tsubl $1,%0\n\t" \
"jne _L_mutex_unlock_%=\n\t" \ "jne _L_mutex_unlock_%=\n\t" \
@ -459,7 +459,7 @@ extern int lll_unlock_wake_cb (int *__futex) attribute_hidden;
"1:\tmovl %1, %%eax\n\t" \ "1:\tmovl %1, %%eax\n\t" \
LLL_ENTER_KERNEL \ LLL_ENTER_KERNEL \
"cmpl $0, (%%ebx)\n\t" \ "cmpl $0, (%%ebx)\n\t" \
"jne,pn 1b\n\t" \ "jne 1b\n\t" \
LLL_EBX_LOAD \ LLL_EBX_LOAD \
: "=&a" (__ignore) \ : "=&a" (__ignore) \
: "i" (SYS_futex), LLL_EBX_REG (&tid), "S" (0), \ : "i" (SYS_futex), LLL_EBX_REG (&tid), "S" (0), \