Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/net/net Fix (a kind of) violation of strict aliasing r...



details:   https://anonhg.NetBSD.org/src/rev/09b4e757567f
branches:  trunk
changeset: 1025167:09b4e757567f
user:      rin <rin%NetBSD.org@localhost>
date:      Mon Nov 08 10:57:09 2021 +0000

description:
Fix (a kind of) violation of strict aliasing rule.

Due to the rule, "sin" and "sin6" can be treated as restrict pointers.
Compilers seem to be confused by structure copy for those pointed by
them before assignments.

For aarch64eb, GCC 9 and 10 compile t_tcp.c rev 1.11 into a code, where
fetch for "sin6->sin6_port" is preceding the structure copy "ss = bs".
This results in failure of connect(2) with EADDRNOOTAVAIL.

diffstat:

 tests/net/net/t_tcp.c |  9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diffs (36 lines):

diff -r c1467edf99ab -r 09b4e757567f tests/net/net/t_tcp.c
--- a/tests/net/net/t_tcp.c     Mon Nov 08 10:19:42 2021 +0000
+++ b/tests/net/net/t_tcp.c     Mon Nov 08 10:57:09 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_tcp.c,v 1.11 2019/10/26 23:08:27 christos Exp $      */
+/*     $NetBSD: t_tcp.c,v 1.12 2021/11/08 10:57:09 rin Exp $   */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __RCSID
-__RCSID("$Id: t_tcp.c,v 1.11 2019/10/26 23:08:27 christos Exp $");
+__RCSID("$Id: t_tcp.c,v 1.12 2021/11/08 10:57:09 rin Exp $");
 #endif
 
 /* Example code. Should block; does with accept not accept4_. */
@@ -139,15 +139,14 @@
                FAIL("socket");
 
        if (sfamily == AF_INET6 && cfamily == AF_INET) {
-               ss = bs;
-               sin6 = (void *)&ss;
+               in_port_t port = ((struct sockaddr_in6 *)&bs)->sin6_port;
                sin = (void *)&bs;
                addrlen = sizeof(*sin);
 #ifdef BSD4_4
                sin->sin_len = sizeof(*sin);
 #endif
                sin->sin_family = AF_INET;
-               sin->sin_port = sin6->sin6_port;
+               sin->sin_port = port;
                sin->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
        }
 



Home | Main Index | Thread Index | Old Index