Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 3 Dec 2016 18:40:40 +0000 (UTC)
From:      Ngie Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r309498 - stable/10/lib/libc/rpc
Message-ID:  <201612031840.uB3Ieet2045355@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Sat Dec  3 18:40:39 2016
New Revision: 309498
URL: https://svnweb.freebsd.org/changeset/base/309498

Log:
  MFC r296386:
  r296386 (by pfg):
  
  Work around aliasing issues detected in modern GCC.
  
  Avoid casting gymnastics that lead to pointer aliasing by introducing an
  inline function as done in NetBSD (but without #if0'd WIP code).
  
  Obtained from:	NetBSD (CVS Rev. 1.24, 1.25)

Modified:
  stable/10/lib/libc/rpc/clnt_vc.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/rpc/clnt_vc.c
==============================================================================
--- stable/10/lib/libc/rpc/clnt_vc.c	Sat Dec  3 18:26:41 2016	(r309497)
+++ stable/10/lib/libc/rpc/clnt_vc.c	Sat Dec  3 18:40:39 2016	(r309498)
@@ -503,6 +503,20 @@ clnt_vc_abort(CLIENT *cl)
 {
 }
 
+static __inline void
+htonlp(void *dst, const void *src, uint32_t incr)
+{
+	/* We are aligned, so we think */
+	*(uint32_t *)dst = htonl(*(const uint32_t *)src + incr);
+}
+
+static __inline void
+ntohlp(void *dst, const void *src)
+{
+	/* We are aligned, so we think */
+	*(uint32_t *)dst = htonl(*(const uint32_t *)src);
+}
+
 static bool_t
 clnt_vc_control(CLIENT *cl, u_int request, void *info)
 {
@@ -577,14 +591,12 @@ clnt_vc_control(CLIENT *cl, u_int reques
 		 * first element in the call structure
 		 * This will get the xid of the PREVIOUS call
 		 */
-		*(u_int32_t *)info =
-		    ntohl(*(u_int32_t *)(void *)&ct->ct_u.ct_mcalli);
+		ntohlp(info, &ct->ct_u.ct_mcalli);
 		break;
 	case CLSET_XID:
 		/* This will set the xid of the NEXT call */
-		*(u_int32_t *)(void *)&ct->ct_u.ct_mcalli =
-		    htonl(*((u_int32_t *)info) + 1);
 		/* increment by 1 as clnt_vc_call() decrements once */
+		htonlp(&ct->ct_u.ct_mcalli, info, 1);
 		break;
 	case CLGET_VERS:
 		/*
@@ -593,15 +605,11 @@ clnt_vc_control(CLIENT *cl, u_int reques
 		 * begining of the RPC header. MUST be changed if the
 		 * call_struct is changed
 		 */
-		*(u_int32_t *)info =
-		    ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
-		    4 * BYTES_PER_XDR_UNIT));
+		ntohlp(info, ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT);
 		break;
 
 	case CLSET_VERS:
-		*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
-		    4 * BYTES_PER_XDR_UNIT) =
-		    htonl(*(u_int32_t *)info);
+		htonlp(ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT, info, 0);
 		break;
 
 	case CLGET_PROG:
@@ -611,15 +619,11 @@ clnt_vc_control(CLIENT *cl, u_int reques
 		 * begining of the RPC header. MUST be changed if the
 		 * call_struct is changed
 		 */
-		*(u_int32_t *)info =
-		    ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
-		    3 * BYTES_PER_XDR_UNIT));
+		ntohlp(info, ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT);
 		break;
 
 	case CLSET_PROG:
-		*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc +
-		    3 * BYTES_PER_XDR_UNIT) =
-		    htonl(*(u_int32_t *)info);
+		htonlp(ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT, info, 0);
 		break;
 
 	default:



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