Update.
	* sunrpc/clnt_udp.c (is_network_up): Use getifaddrs instead of ioctl.
	* sunrpc/get_myaddr.c (get_myaddress): Likewise.
	* sunrpc/pmap_clnt.c (__get_myaddress): Likewise.
	* sunrpc/pmap_rmt.c (getbroadcastnets): Likewise.  Change interface
	to avoid buffer overrun and remove now useless parameters.
	(clnt_broadcast): Adjust caller.  [BZ #381].
This commit is contained in:
Ulrich Drepper 2004-09-26 11:11:28 +00:00
parent 6497a1d081
commit 412c954afa
5 changed files with 89 additions and 125 deletions

View File

@ -1,5 +1,12 @@
2004-09-26 Ulrich Drepper <drepper@redhat.com> 2004-09-26 Ulrich Drepper <drepper@redhat.com>
* sunrpc/clnt_udp.c (is_network_up): Use getifaddrs instead of ioctl.
* sunrpc/get_myaddr.c (get_myaddress): Likewise.
* sunrpc/pmap_clnt.c (__get_myaddress): Likewise.
* sunrpc/pmap_rmt.c (getbroadcastnets): Likewise. Change interface
to avoid buffer overrun and remove now useless parameters.
(clnt_broadcast): Adjust caller. [BZ #381].
* sysdeps/generic/s_fdim.c: Handle +inf/+inf * sysdeps/generic/s_fdim.c: Handle +inf/+inf
* sysdeps/generic/s_fdimf.c: Likewise. * sysdeps/generic/s_fdimf.c: Likewise.
* sysdeps/generic/s_fdiml.c: Likewise. * sysdeps/generic/s_fdiml.c: Likewise.

View File

@ -50,6 +50,7 @@ static char sccsid[] = "@(#)clnt_udp.c 1.39 87/08/11 Copyr 1984 Sun Micro";
#include <errno.h> #include <errno.h>
#include <rpc/pmap_clnt.h> #include <rpc/pmap_clnt.h>
#include <net/if.h> #include <net/if.h>
#include <ifaddrs.h>
#ifdef USE_IN_LIBIO #ifdef USE_IN_LIBIO
# include <wchar.h> # include <wchar.h>
#endif #endif
@ -234,28 +235,24 @@ INTDEF (clntudp_create)
static int static int
is_network_up (int sock) is_network_up (int sock)
{ {
struct ifconf ifc; struct ifaddrs *ifa;
char buf[UDPMSGSIZE];
struct ifreq ifreq, *ifr;
int n;
ifc.ifc_len = sizeof (buf); if (getifaddrs (&ifa) != 0)
ifc.ifc_buf = buf; return 0;
if (__ioctl(sock, SIOCGIFCONF, (char *) &ifc) == 0)
struct ifaddrs *run = ifa;
while (run != NULL)
{ {
ifr = ifc.ifc_req; if ((run->ifa_flags & IFF_UP) != 0
for (n = ifc.ifc_len / sizeof (struct ifreq); n > 0; n--, ifr++) && run->ifa_addr->sa_family == AF_INET)
{ break;
ifreq = *ifr;
if (__ioctl (sock, SIOCGIFFLAGS, (char *) &ifreq) < 0)
break;
if ((ifreq.ifr_flags & IFF_UP) run = run->ifa_next;
&& ifr->ifr_addr.sa_family == AF_INET)
return 1;
}
} }
return 0;
freeifaddrs (ifa);
return run != NULL;
} }
static enum clnt_stat static enum clnt_stat

View File

@ -46,6 +46,7 @@ static char sccsid[] = "@(#)get_myaddress.c 1.4 87/08/11 Copyr 1984 Sun Micro";
#include <unistd.h> #include <unistd.h>
#include <libintl.h> #include <libintl.h>
#include <net/if.h> #include <net/if.h>
#include <ifaddrs.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
/* Order of following two #includes reversed by roland@gnu */ /* Order of following two #includes reversed by roland@gnu */
#include <netinet/in.h> #include <netinet/in.h>
@ -60,50 +61,42 @@ static char sccsid[] = "@(#)get_myaddress.c 1.4 87/08/11 Copyr 1984 Sun Micro";
void void
get_myaddress (struct sockaddr_in *addr) get_myaddress (struct sockaddr_in *addr)
{ {
int s; struct ifaddrs *ifa;
char buf[BUFSIZ];
struct ifconf ifc;
struct ifreq ifreq, *ifr;
int len, loopback = 0;
if ((s = __socket (AF_INET, SOCK_DGRAM, 0)) < 0) if (getifaddrs (&ifa) == 0)
{ {
perror ("get_myaddress: socket"); perror ("get_myaddress: getifaddrs");
exit (1);
}
ifc.ifc_len = sizeof (buf);
ifc.ifc_buf = buf;
if (__ioctl (s, SIOCGIFCONF, (char *) &ifc) < 0)
{
perror (_("get_myaddress: ioctl (get interface configuration)"));
exit (1); exit (1);
} }
int loopback = 0;
struct ifaddrs *run;
again: again:
ifr = ifc.ifc_req; run = ifa;
for (len = ifc.ifc_len; len; len -= sizeof ifreq) while (run != NULL)
{ {
ifreq = *ifr; if ((run->ifa_flags & IFF_UP) && run->ifa_addr->sa_family == AF_INET
if (__ioctl (s, SIOCGIFFLAGS, (char *) &ifreq) < 0) && (!(run->ifa_flags & IFF_LOOPBACK)
|| (loopback == 1 && (run->ifa_flags & IFF_LOOPBACK))))
{ {
perror ("get_myaddress: ioctl"); *addr = *((struct sockaddr_in *) run->ifa_addr);
exit (1);
}
if ((ifreq.ifr_flags & IFF_UP) && (ifr->ifr_addr.sa_family == AF_INET)
&& (!(ifreq.ifr_flags & IFF_LOOPBACK) ||
(loopback == 1 && (ifreq.ifr_flags & IFF_LOOPBACK))))
{
*addr = *((struct sockaddr_in *) &ifr->ifr_addr);
addr->sin_port = htons (PMAPPORT); addr->sin_port = htons (PMAPPORT);
__close (s); goto out;
return;
} }
ifr++;
run = run->ifa_next;
} }
if (loopback == 0) if (loopback == 0)
{ {
loopback = 1; loopback = 1;
goto again; goto again;
} }
__close (s); out:
freeifaddrs (ifa);
/* The function is horribly specified. It does not return any error
if no interface is up. Probably this won't happen (at least
loopback is there) but still... */
} }

View File

@ -38,6 +38,7 @@
#include <unistd.h> #include <unistd.h>
#include <libintl.h> #include <libintl.h>
#include <net/if.h> #include <net/if.h>
#include <ifaddrs.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -54,52 +55,41 @@
static bool_t static bool_t
__get_myaddress (struct sockaddr_in *addr) __get_myaddress (struct sockaddr_in *addr)
{ {
int s; struct ifaddrs *ifa;
char buf[BUFSIZ];
struct ifconf ifc;
struct ifreq ifreq, *ifr;
int len, loopback = 1;
if ((s = __socket (AF_INET, SOCK_DGRAM, 0)) < 0) if (getifaddrs (&ifa) == 0)
{ {
perror ("__get_myaddress: socket"); perror ("get_myaddress: getifaddrs");
exit (1);
}
ifc.ifc_len = sizeof (buf);
ifc.ifc_buf = buf;
if (__ioctl (s, SIOCGIFCONF, (char *) &ifc) < 0)
{
perror (_("__get_myaddress: ioctl (get interface configuration)"));
exit (1); exit (1);
} }
int loopback = 1;
struct ifaddrs *run;
again: again:
ifr = ifc.ifc_req; run = ifa;
for (len = ifc.ifc_len; len; len -= sizeof ifreq) while (run != NULL)
{ {
ifreq = *ifr; if ((run->ifa_flags & IFF_UP) && run->ifa_addr->sa_family == AF_INET
if (__ioctl (s, SIOCGIFFLAGS, (char *) &ifreq) < 0) && ((run->ifa_flags & IFF_LOOPBACK) || loopback == 0))
{ {
perror ("__get_myaddress: ioctl"); *addr = *((struct sockaddr_in *) run->ifa_addr);
exit (1); addr->sin_port = htons (PMAPPORT);
} goto out;
if ((ifreq.ifr_flags & IFF_UP) && (ifr->ifr_addr.sa_family == AF_INET) }
&& ((ifreq.ifr_flags & IFF_LOOPBACK) || (loopback == 0)))
{ run = run->ifa_next;
*addr = *((struct sockaddr_in *) &ifr->ifr_addr);
addr->sin_port = htons (PMAPPORT);
__close (s);
return TRUE;
}
ifr++;
} }
if (loopback == 1) if (loopback == 1)
{ {
loopback = 0; loopback = 0;
goto again; goto again;
} }
__close (s); out:
return FALSE; freeifaddrs (ifa);
return run == NULL ? FALSE : TRUE;
} }

View File

@ -53,6 +53,7 @@ static char sccsid[] = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
#undef _POSIX_SOURCE /* Ultrix <sys/param.h> needs --roland@gnu */ #undef _POSIX_SOURCE /* Ultrix <sys/param.h> needs --roland@gnu */
#include <sys/param.h> /* Ultrix needs before net/if --roland@gnu */ #include <sys/param.h> /* Ultrix needs before net/if --roland@gnu */
#include <net/if.h> #include <net/if.h>
#include <ifaddrs.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#define MAX_BROADCAST_SIZE 1400 #define MAX_BROADCAST_SIZE 1400
@ -174,55 +175,31 @@ INTDEF(xdr_rmtcallres)
static int static int
internal_function internal_function
getbroadcastnets (struct in_addr *addrs, int sock, char *buf) getbroadcastnets (struct in_addr *addrs, int naddrs)
/* int sock: any valid socket will do */
/* char *buf: why allocate more when we can use existing... */
{ {
struct ifconf ifc; struct ifaddrs *ifa;
struct ifreq ifreq, *ifr;
struct sockaddr_in *sin;
int n, i;
ifc.ifc_len = UDPMSGSIZE; if (getifaddrs (&ifa) == 0)
ifc.ifc_buf = buf;
if (__ioctl (sock, SIOCGIFCONF, (char *) &ifc) < 0)
{ {
perror (_("broadcast: ioctl (get interface configuration)")); perror ("broadcast: getifaddrs");
return (0); return 0;
} }
ifr = ifc.ifc_req;
for (i = 0, n = ifc.ifc_len / sizeof (struct ifreq); n > 0; n--, ifr++) int i = 0;
struct ifaddrs *run = ifa;
while (run != NULL && i < naddrs)
{ {
ifreq = *ifr; if ((run->ifa_flags & IFF_BROADCAST) != 0
if (__ioctl (sock, SIOCGIFFLAGS, (char *) &ifreq) < 0) && (run->ifa_flags & IFF_UP) != 0
{ && run->ifa_addr->sa_family == AF_INET)
perror (_("broadcast: ioctl (get interface flags)")); /* Copy the broadcast address. */
continue; addrs[i++] = ((struct sockaddr_in *) run->ifa_broadaddr)->sin_addr;
}
if ((ifreq.ifr_flags & IFF_BROADCAST) && run = run->ifa_next;
(ifreq.ifr_flags & IFF_UP) &&
ifr->ifr_addr.sa_family == AF_INET)
{
sin = (struct sockaddr_in *) &ifr->ifr_addr;
#ifdef SIOCGIFBRDADDR /* 4.3BSD */
if (__ioctl (sock, SIOCGIFBRDADDR, (char *) &ifreq) < 0)
{
addrs[i++] = inet_makeaddr (inet_netof
/* Changed to pass struct instead of s_addr member
by roland@gnu. */
(sin->sin_addr), INADDR_ANY);
}
else
{
addrs[i++] = ((struct sockaddr_in *)
&ifreq.ifr_addr)->sin_addr;
}
#else /* 4.2 BSD */
addrs[i++] = inet_makeaddr (inet_netof
(sin->sin_addr.s_addr), INADDR_ANY);
#endif
}
} }
freeifaddrs (ifa);
return i; return i;
} }
@ -280,7 +257,7 @@ clnt_broadcast (prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
#endif /* def SO_BROADCAST */ #endif /* def SO_BROADCAST */
fd.fd = sock; fd.fd = sock;
fd.events = POLLIN; fd.events = POLLIN;
nets = getbroadcastnets (addrs, sock, inbuf); nets = getbroadcastnets (addrs, sizeof (addrs) / sizeof (addrs[0]));
__bzero ((char *) &baddr, sizeof (baddr)); __bzero ((char *) &baddr, sizeof (baddr));
baddr.sin_family = AF_INET; baddr.sin_family = AF_INET;
baddr.sin_port = htons (PMAPPORT); baddr.sin_port = htons (PMAPPORT);