svn commit: r313401 - head/sys/netinet

Eric van Gyzen vangyzen at FreeBSD.org
Tue Feb 7 18:57:58 UTC 2017


Author: vangyzen
Date: Tue Feb  7 18:57:57 2017
New Revision: 313401
URL: https://svnweb.freebsd.org/changeset/base/313401

Log:
  Fix garbage IP addresses in UDP log_in_vain messages
  
  If multiple threads emit a UDP log_in_vain message concurrently,
  the IP addresses could be garbage due to concurrent usage of a
  single string buffer inside inet_ntoa().  Use inet_ntoa_r() with
  two stack buffers instead.
  
  Reported by:	Mark Martinec <Mark.Martinec+freebsd at ijs.si>
  MFC after:	3 days
  Relnotes:	yes
  Sponsored by:	Dell EMC

Modified:
  head/sys/netinet/udp_usrreq.c

Modified: head/sys/netinet/udp_usrreq.c
==============================================================================
--- head/sys/netinet/udp_usrreq.c	Tue Feb  7 18:57:52 2017	(r313400)
+++ head/sys/netinet/udp_usrreq.c	Tue Feb  7 18:57:57 2017	(r313401)
@@ -667,13 +667,13 @@ udp_input(struct mbuf **mp, int *offp, i
 		    INPLOOKUP_RLOCKPCB, ifp, m);
 	if (inp == NULL) {
 		if (udp_log_in_vain) {
-			char buf[4*sizeof "123"];
+			char src[INET_ADDRSTRLEN];
+			char dst[INET_ADDRSTRLEN];
 
-			strcpy(buf, inet_ntoa(ip->ip_dst));
 			log(LOG_INFO,
 			    "Connection attempt to UDP %s:%d from %s:%d\n",
-			    buf, ntohs(uh->uh_dport), inet_ntoa(ip->ip_src),
-			    ntohs(uh->uh_sport));
+			    inet_ntoa_r(ip->ip_dst, dst), ntohs(uh->uh_dport),
+			    inet_ntoa_r(ip->ip_src, src), ntohs(uh->uh_sport));
 		}
 		UDPSTAT_INC(udps_noport);
 		if (m->m_flags & (M_BCAST | M_MCAST)) {


More information about the svn-src-all mailing list