Date: Sun, 20 Sep 2015 22:27:19 +0000 (UTC) From: Hiroki Sato <hrs@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r288048 - stable/10/usr.sbin/inetd Message-ID: <201509202227.t8KMRJF4039259@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hrs Date: Sun Sep 20 22:27:19 2015 New Revision: 288048 URL: https://svnweb.freebsd.org/changeset/base/288048 Log: MFC 281734-281736,287997-287998: - Fix a crash on a rpc entry when an IPv6 address is explicitly specified in -a flag. - Fix a bug that sockaddr_in was used where sockaddr_in6 should have been used. This was not actually harmful because offsetof(struct sockaddr_in, sin_port) is equal to offsetof(struct sockaddr_in6, sin6_port). - Remove unused union p_un. - Use NI_MAXHOST-long buffer for getnameinfo(). Although INET6_ADDRSTRLEN was designed to hold the longest IPv6 address in IPv4-mapped address format a long time ago, getnameinfo() can return scope identifier in addition to it. Modified: stable/10/usr.sbin/inetd/inetd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.sbin/inetd/inetd.c ============================================================================== --- stable/10/usr.sbin/inetd/inetd.c Sun Sep 20 21:39:55 2015 (r288047) +++ stable/10/usr.sbin/inetd/inetd.c Sun Sep 20 22:27:19 2015 (r288048) @@ -327,16 +327,7 @@ main(int argc, char **argv) struct request_info req; int denied; char *service = NULL; - union { - struct sockaddr peer_un; - struct sockaddr_in peer_un4; - struct sockaddr_in6 peer_un6; - struct sockaddr_storage peer_max; - } p_un; -#define peer p_un.peer_un -#define peer4 p_un.peer_un4 -#define peer6 p_un.peer_un6 -#define peermax p_un.peer_max + struct sockaddr_storage peer; int i; struct addrinfo hints, *res; const char *servname; @@ -656,24 +647,24 @@ main(int argc, char **argv) } else ctrl = sep->se_fd; if (dolog && !ISWRAP(sep)) { - char pname[INET6_ADDRSTRLEN] = "unknown"; + char pname[NI_MAXHOST] = "unknown"; socklen_t sl; - sl = sizeof peermax; + sl = sizeof(peer); if (getpeername(ctrl, (struct sockaddr *) - &peermax, &sl)) { - sl = sizeof peermax; + &peer, &sl)) { + sl = sizeof(peer); if (recvfrom(ctrl, buf, sizeof(buf), MSG_PEEK, - (struct sockaddr *)&peermax, + (struct sockaddr *)&peer, &sl) >= 0) { - getnameinfo((struct sockaddr *)&peermax, - peer.sa_len, + getnameinfo((struct sockaddr *)&peer, + peer.ss_len, pname, sizeof(pname), NULL, 0, NI_NUMERICHOST); } } else { - getnameinfo((struct sockaddr *)&peermax, - peer.sa_len, + getnameinfo((struct sockaddr *)&peer, + peer.ss_len, pname, sizeof(pname), NULL, 0, NI_NUMERICHOST); } @@ -1761,9 +1752,7 @@ more: strlen(sep->se_proto) + 1 - 4); sep->se_rpc = 1; sep->se_rpc_prog = sep->se_rpc_lowvers = - sep->se_rpc_lowvers = 0; - memcpy(&sep->se_ctrladdr4, bind_sa4, - sizeof(sep->se_ctrladdr4)); + sep->se_rpc_highvers = 0; if ((versp = strrchr(sep->se_service, '/'))) { *versp++ = '\0'; switch (sscanf(versp, "%u-%u", @@ -2108,7 +2097,7 @@ inetd_setproctitle(const char *a, int s) { socklen_t size; struct sockaddr_storage ss; - char buf[80], pbuf[INET6_ADDRSTRLEN]; + char buf[80], pbuf[NI_MAXHOST]; size = sizeof(ss); if (getpeername(s, (struct sockaddr *)&ss, &size) == 0) { @@ -2124,7 +2113,7 @@ int check_loop(const struct sockaddr *sa, const struct servtab *sep) { struct servtab *se2; - char pname[INET6_ADDRSTRLEN]; + char pname[NI_MAXHOST]; for (se2 = servtab; se2; se2 = se2->se_next) { if (!se2->se_bi || se2->se_socktype != SOCK_DGRAM) @@ -2138,8 +2127,8 @@ check_loop(const struct sockaddr *sa, co continue; #ifdef INET6 case AF_INET6: - if (((const struct sockaddr_in *)sa)->sin_port == - se2->se_ctrladdr4.sin_port) + if (((const struct sockaddr_in6 *)sa)->sin6_port == + se2->se_ctrladdr6.sin6_port) goto isloop; continue; #endif @@ -2338,7 +2327,7 @@ cpmip(const struct servtab *sep, int ctr } } if ((cnt * 60) / (CHTSIZE * CHTGRAN) > sep->se_maxcpm) { - char pname[INET6_ADDRSTRLEN]; + char pname[NI_MAXHOST]; getnameinfo((struct sockaddr *)&rss, ((struct sockaddr *)&rss)->sa_len,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201509202227.t8KMRJF4039259>