summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2016-06-08 15:41:39 +0000
committerngie <ngie@FreeBSD.org>2016-06-08 15:41:39 +0000
commit88d772455aaf766e02e921fffd015172aec0f0bb (patch)
tree7f207fa606c265432ca6858860d2b029a4128ad2 /usr.sbin
parent47cb06bc0c53166cbc76421de660b94a24ea8661 (diff)
downloadFreeBSD-src-88d772455aaf766e02e921fffd015172aec0f0bb.zip
FreeBSD-src-88d772455aaf766e02e921fffd015172aec0f0bb.tar.gz
MFC r300867,r300932,r300934,r300941,r300972,r300973:
r300867: Only expose `hint_uaddr` in the ND_DEBUG case This fixes a -Wunused-but-set-variable warning with gcc r300932: Catch malloc(3) errors and socket(2) errors - malloc failing will result in a delayed segfault - socket failing will result in delayed failures with setsockopt Exit in the event that either of these high-level conditions are met. CID: 976288, 976321, 976858 r300934: Plug leak with ifp by calling freeifaddrs after calling getifaddrs Obtained from: NetBSD v1.18 r300941: Don't leak res in network_init(..) Call freeaddrinfo on it after it's been used CID: 1225050 r300972 (by markj): Fix rpcbind init after r300941. - getaddrinfo() sets res = NULL on failure and freeaddrinfo() always dereferences its argument, so we should only free the address list after a successful call. - Address a second potential leak caused by getaddrinfo(AF_INET6) overwriting the address list returned by getaddrinfo(AF_INET). X-MFC-With: r300941 r300973: Follow up to r300932 In the event MK_INET6 != no in userspace, but is disabled in the kernel, or if there aren't any IPv6 addresses configured in userspace (for lo0 and all physical interfaces), rpcbind would terminate immediately instead of silently failing on Skip over the IPv6 block to its respective cleanup with freeifaddrs if creating the socket failed instead of terminating rpcbind immediately
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/rpcbind/util.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/usr.sbin/rpcbind/util.c b/usr.sbin/rpcbind/util.c
index da6a5ab..24ac1ef 100644
--- a/usr.sbin/rpcbind/util.c
+++ b/usr.sbin/rpcbind/util.c
@@ -119,7 +119,9 @@ addrmerge(struct netbuf *caller, const char *serv_uaddr, const char *clnt_uaddr,
struct sockaddr_storage ss;
struct netconfig *nconf;
char *caller_uaddr = NULL;
+#ifdef ND_DEBUG
const char *hint_uaddr = NULL;
+#endif
char *ret = NULL;
int bestif_goodness;
@@ -140,13 +142,17 @@ addrmerge(struct netbuf *caller, const char *serv_uaddr, const char *clnt_uaddr,
*/
hint_sa = NULL;
if (clnt_uaddr != NULL) {
+#ifdef ND_DEBUG
hint_uaddr = clnt_uaddr;
+#endif
if ((hint_nbp = uaddr2taddr(nconf, clnt_uaddr)) == NULL)
goto freeit;
hint_sa = hint_nbp->buf;
}
if (hint_sa == NULL || hint_sa->sa_family != caller_sa->sa_family) {
+#ifdef ND_DEBUG
hint_uaddr = caller_uaddr;
+#endif
hint_sa = caller->buf;
}
@@ -330,8 +336,10 @@ network_init(void)
if (local_in4 == NULL) {
if (debugging)
fprintf(stderr, "can't alloc local ip4 addr\n");
+ exit(1);
}
memcpy(local_in4, res->ai_addr, sizeof *local_in4);
+ freeaddrinfo(res);
}
#ifdef INET6
@@ -345,8 +353,10 @@ network_init(void)
if (local_in6 == NULL) {
if (debugging)
fprintf(stderr, "can't alloc local ip6 addr\n");
+ exit(1);
}
memcpy(local_in6, res->ai_addr, sizeof *local_in6);
+ freeaddrinfo(res);
}
/*
@@ -359,6 +369,11 @@ network_init(void)
inet_pton(AF_INET6, RPCB_MULTICAST_ADDR, &mreq6.ipv6mr_multiaddr);
s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
+ if (s == -1) {
+ if (debugging)
+ fprintf(stderr, "couldn't create ip6 socket");
+ goto done_inet6;
+ }
/*
* Loop through all interfaces. For each IPv6 multicast-capable
@@ -380,6 +395,8 @@ network_init(void)
if (debugging)
perror("setsockopt v6 multicast");
}
+done_inet6:
+ freeifaddrs(ifp);
#endif
/* close(s); */
OpenPOWER on IntegriCloud