* nis/nss_nisplus/nisplus-network.c (_nss_nisplus_getnetbyaddr_r):

Better sized buffers.  Correct error case handling.
This commit is contained in:
Ulrich Drepper 2005-12-03 22:36:14 +00:00
parent 8e64faef03
commit 9069c5e963
2 changed files with 13 additions and 17 deletions

View File

@ -1,5 +1,7 @@
2005-12-03 Ulrich Drepper <drepper@redhat.com> 2005-12-03 Ulrich Drepper <drepper@redhat.com>
* nis/nss_nisplus/nisplus-network.c (_nss_nisplus_getnetbyaddr_r):
Better sized buffers. Correct error case handling.
* nis/nis_error.c (nis_sperror_r): Let snprintf determine whether * nis/nis_error.c (nis_sperror_r): Let snprintf determine whether
there is an overflow. there is an overflow.
* nis/nss_nisplus/nisplus-service.c: Fix locking to use * nis/nss_nisplus/nisplus-service.c: Fix locking to use

View File

@ -416,32 +416,28 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
} }
{ {
int parse_res, retval; char buf[27 + tablename_len];
nis_result *result; char buf2[18];
char buf[1024 + tablename_len];
struct in_addr in;
char buf2[256];
int b2len;
int olderr = errno; int olderr = errno;
in = inet_makeaddr (addr, 0); struct in_addr in = inet_makeaddr (addr, 0);
strcpy (buf2, inet_ntoa (in)); strcpy (buf2, inet_ntoa (in));
b2len = strlen (buf2); size_t b2len = strlen (buf2);
while (1) while (1)
{ {
sprintf (buf, "[addr=%s],%s", buf2, tablename_val); snprintf (buf, sizeof (buf), "[addr=%s],%s", buf2, tablename_val);
result = nis_list (buf, EXPAND_NAME, NULL, NULL); nis_result *result = nis_list (buf, EXPAND_NAME, NULL, NULL);
if (result == NULL) if (result == NULL)
{ {
__set_errno (ENOMEM); __set_errno (ENOMEM);
return NSS_STATUS_TRYAGAIN; return NSS_STATUS_TRYAGAIN;
} }
retval = niserr2nss (result->status); enum nss_status retval = niserr2nss (result->status);
if (retval != NSS_STATUS_SUCCESS) if (__builtin_expect (retval != NSS_STATUS_SUCCESS, 0))
{ {
if (buf2[b2len -2] == '.' && buf2[b2len -1] == '0') if (b2len > 2 && buf2[b2len - 2] == '.' && buf2[b2len - 1] == '0')
{ {
/* Try again, but with trailing dot(s) /* Try again, but with trailing dot(s)
removed (one by one) */ removed (one by one) */
@ -449,8 +445,6 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
b2len -= 2; b2len -= 2;
continue; continue;
} }
else
return NSS_STATUS_NOTFOUND;
if (retval == NSS_STATUS_TRYAGAIN) if (retval == NSS_STATUS_TRYAGAIN)
{ {
@ -463,8 +457,8 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
return retval; return retval;
} }
parse_res = _nss_nisplus_parse_netent (result, network, buffer, int parse_res = _nss_nisplus_parse_netent (result, network, buffer,
buflen, errnop); buflen, errnop);
nis_freeresult (result); nis_freeresult (result);