diff options
author | vangyzen <vangyzen@FreeBSD.org> | 2017-02-10 16:11:11 +0000 |
---|---|---|
committer | vangyzen <vangyzen@FreeBSD.org> | 2017-02-10 16:11:11 +0000 |
commit | 58b22c1b2c60ef4d8f1b33b394a9b44e04507ca1 (patch) | |
tree | 153013e288517cc1a32f229b7c796abff8d8ea81 /sys/netinet | |
parent | 24a80a3173e1990c42b9f5db56d2736189decc2f (diff) | |
download | FreeBSD-src-58b22c1b2c60ef4d8f1b33b394a9b44e04507ca1.zip FreeBSD-src-58b22c1b2c60ef4d8f1b33b394a9b44e04507ca1.tar.gz |
MFC r313401
Fix garbage IP addresses in UDP log_in_vain messages
If multiple threads emit a UDP log_in_vain message concurrently,
or indeed call inet_ntoa() for any other reason,
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.
Relnotes: yes
Sponsored by: Dell EMC
Diffstat (limited to 'sys/netinet')
-rw-r--r-- | sys/netinet/udp_usrreq.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 79a2166..f43e567 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -647,13 +647,13 @@ udp_input(struct mbuf *m, int off) 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)) { |