Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Aug 2019 18:00:18 +0000 (UTC)
From:      Alan Somers <asomers@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r351461 - head/sbin/ping
Message-ID:  <201908241800.x7OI0I7X014562@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: asomers
Date: Sat Aug 24 18:00:18 2019
New Revision: 351461
URL: https://svnweb.freebsd.org/changeset/base/351461

Log:
  ping: fix unaligned access to ancillary data
  
  Use CMSG_FIRSTHDR rather than assume that an array is correctly aligned.
  Fixes warnings on sparc64 and powerpcspe.
  
  Submitted by:	Ján Sučan <sucanjan@gmail.com>
  MFH:		2 weeks
  Sponsored by:	Google LLC (Google Summer of Code 2019)
  Differential Revision:	https://reviews.freebsd.org/D21406

Modified:
  head/sbin/ping/ping.c

Modified: head/sbin/ping/ping.c
==============================================================================
--- head/sbin/ping/ping.c	Sat Aug 24 16:44:47 2019	(r351460)
+++ head/sbin/ping/ping.c	Sat Aug 24 18:00:18 2019	(r351461)
@@ -875,6 +875,7 @@ main(int argc, char *const *argv)
 	msg.msg_iovlen = 1;
 #ifdef SO_TIMESTAMP
 	msg.msg_control = (caddr_t)ctrl;
+	msg.msg_controllen = sizeof(ctrl);
 #endif
 	iov.iov_base = packet;
 	iov.iov_len = IP_MAXPACKET;
@@ -920,9 +921,7 @@ main(int argc, char *const *argv)
 		if (n == 1) {
 			struct timespec *tv = NULL;
 #ifdef SO_TIMESTAMP
-			struct cmsghdr *cmsg = (struct cmsghdr *)&ctrl;
-
-			msg.msg_controllen = sizeof(ctrl);
+			struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
 #endif
 			msg.msg_namelen = sizeof(from);
 			if ((cc = recvmsg(srecv, &msg, 0)) < 0) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201908241800.x7OI0I7X014562>