Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Aug 2019 16:55:06 +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: r351033 - head/sbin/ping
Message-ID:  <201908141655.x7EGt6dn046000@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: asomers
Date: Wed Aug 14 16:55:06 2019
New Revision: 351033
URL: https://svnweb.freebsd.org/changeset/base/351033

Log:
  ping: Make in_cksum() operate on u_char buffer
  
  This fixes -Wcast-align errors for in_cksum() calls when compiled with
  WARNS=6.
  
  Submitted by:	Ján Sučan <sucanjan@gmail.com>
  MFC after:	2 weeks
  Sponsored by:	Google, inc. (Google Summer of Code 2019)
  Differential Revision:	https://reviews.freebsd.org/D21261

Modified:
  head/sbin/ping/ping.c

Modified: head/sbin/ping/ping.c
==============================================================================
--- head/sbin/ping/ping.c	Wed Aug 14 16:54:51 2019	(r351032)
+++ head/sbin/ping/ping.c	Wed Aug 14 16:55:06 2019	(r351033)
@@ -209,7 +209,7 @@ static volatile sig_atomic_t siginfo_p;
 static cap_channel_t *capdns;
 
 static void fill(char *, char *);
-static u_short in_cksum(u_short *, int);
+static u_short in_cksum(u_char *, int);
 static cap_channel_t *capdns_setup(void);
 static void check_status(void);
 static void finish(void) __dead2;
@@ -1046,13 +1046,13 @@ pinger(void)
 	cc = ICMP_MINLEN + phdr_len + datalen;
 
 	/* compute ICMP checksum here */
-	icp->icmp_cksum = in_cksum((u_short *)icp, cc);
+	icp->icmp_cksum = in_cksum((u_char *)icp, cc);
 
 	if (options & F_HDRINCL) {
 		cc += sizeof(struct ip);
 		ip = (struct ip *)outpackhdr;
 		ip->ip_len = htons(cc);
-		ip->ip_sum = in_cksum((u_short *)outpackhdr, cc);
+		ip->ip_sum = in_cksum(outpackhdr, cc);
 		packet = outpackhdr;
 	}
 	i = send(ssend, (char *)packet, cc, 0);
@@ -1348,10 +1348,10 @@ pr_pack(char *buf, int cc, struct sockaddr_in *from, s
  *	Checksum routine for Internet Protocol family headers (C Version)
  */
 u_short
-in_cksum(u_short *addr, int len)
+in_cksum(u_char *addr, int len)
 {
 	int nleft, sum;
-	u_short *w;
+	u_char *w;
 	union {
 		u_short	us;
 		u_char	uc[2];
@@ -1368,13 +1368,17 @@ in_cksum(u_short *addr, int len)
 	 * carry bits from the top 16 bits into the lower 16 bits.
 	 */
 	while (nleft > 1)  {
-		sum += *w++;
-		nleft -= 2;
+		u_short data;
+
+		memcpy(&data, w, sizeof(data));
+		sum += data;
+		w += sizeof(data);
+		nleft -= sizeof(data);
 	}
 
 	/* mop up an odd byte, if necessary */
 	if (nleft == 1) {
-		last.uc[0] = *(u_char *)w;
+		last.uc[0] = *w;
 		last.uc[1] = 0;
 		sum += last.us;
 	}



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