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
This commit is contained in:
+2
-3
@@ -875,6 +875,7 @@ main(int argc, char *const *argv)
|
|||||||
msg.msg_iovlen = 1;
|
msg.msg_iovlen = 1;
|
||||||
#ifdef SO_TIMESTAMP
|
#ifdef SO_TIMESTAMP
|
||||||
msg.msg_control = (caddr_t)ctrl;
|
msg.msg_control = (caddr_t)ctrl;
|
||||||
|
msg.msg_controllen = sizeof(ctrl);
|
||||||
#endif
|
#endif
|
||||||
iov.iov_base = packet;
|
iov.iov_base = packet;
|
||||||
iov.iov_len = IP_MAXPACKET;
|
iov.iov_len = IP_MAXPACKET;
|
||||||
@@ -920,9 +921,7 @@ main(int argc, char *const *argv)
|
|||||||
if (n == 1) {
|
if (n == 1) {
|
||||||
struct timespec *tv = NULL;
|
struct timespec *tv = NULL;
|
||||||
#ifdef SO_TIMESTAMP
|
#ifdef SO_TIMESTAMP
|
||||||
struct cmsghdr *cmsg = (struct cmsghdr *)&ctrl;
|
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
|
||||||
|
|
||||||
msg.msg_controllen = sizeof(ctrl);
|
|
||||||
#endif
|
#endif
|
||||||
msg.msg_namelen = sizeof(from);
|
msg.msg_namelen = sizeof(from);
|
||||||
if ((cc = recvmsg(srecv, &msg, 0)) < 0) {
|
if ((cc = recvmsg(srecv, &msg, 0)) < 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user