arrfab / rpms / glibc

Forked from rpms/glibc 4 years ago
Clone

Blame SOURCES/glibc-rh1338672.patch

147e83
commit 3375cfafa7961c6ae0e509c31c3b3cef9ad1f03d
147e83
Author: Florian Weimer <fweimer@redhat.com>
147e83
Date:   Mon May 23 19:43:09 2016 +0200
147e83
147e83
    Make padding in struct sockaddr_storage explicit [BZ #20111]
147e83
    
147e83
    This avoids aliasing issues with GCC 6 in -fno-strict-aliasing
147e83
    mode.  (With implicit padding, not all data is copied.)
147e83
    
147e83
    This change makes it explicit that struct sockaddr_storage is
147e83
    only 126 bytes large on m68k (unlike elsewhere, where we end up
147e83
    with the requested 128 bytes).  The new test case makes sure that
147e83
    this does not happen on other architectures.
147e83
147e83
[modified by DJ Delorie <dj@redhat.com> for RHEL]
147e83
147e83
diff -rupN a/bits/sockaddr.h b/bits/sockaddr.h
147e83
--- a/bits/sockaddr.h	2012-12-24 22:02:13.000000000 -0500
147e83
+++ b/bits/sockaddr.h	2017-03-01 16:54:46.606261055 -0500
147e83
@@ -1,4 +1,4 @@
147e83
-/* Definition of `struct sockaddr_*' common members.  Generic/4.2 BSD version.
147e83
+/* Definition of struct sockaddr_* common members and sizes, generic version.
147e83
    Copyright (C) 1995,1996,1997,1998,2000,2001 Free Software Foundation, Inc.
147e83
    This file is part of the GNU C Library.
147e83
 
147e83
@@ -36,4 +36,7 @@ typedef unsigned short int sa_family_t;
147e83
 
147e83
 #define __SOCKADDR_COMMON_SIZE	(sizeof (unsigned short int))
147e83
 
147e83
+/* Size of struct sockaddr_storage.  */
147e83
+#define _SS_SIZE 128
147e83
+
147e83
 #endif	/* bits/sockaddr.h */
147e83
diff -rupN a/bits/socket.h b/bits/socket.h
147e83
--- a/bits/socket.h	2012-12-24 22:02:13.000000000 -0500
147e83
+++ b/bits/socket.h	2017-03-01 16:38:24.861208175 -0500
147e83
@@ -133,20 +133,20 @@ struct sockaddr
147e83
 
147e83
 
147e83
 /* Structure large enough to hold any socket address (with the historical
147e83
-   exception of AF_UNIX).  We reserve 128 bytes.  */
147e83
+   exception of AF_UNIX).  */
147e83
 #if ULONG_MAX > 0xffffffff
147e83
 # define __ss_aligntype	__uint64_t
147e83
 #else
147e83
 # define __ss_aligntype	__uint32_t
147e83
 #endif
147e83
-#define _SS_SIZE	128
147e83
-#define _SS_PADSIZE	(_SS_SIZE - (2 * sizeof (__ss_aligntype)))
147e83
+#define _SS_PADSIZE \
147e83
+  (_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype))
147e83
 
147e83
 struct sockaddr_storage
147e83
   {
147e83
     __SOCKADDR_COMMON (ss_);	/* Address family, etc.  */
147e83
-    __ss_aligntype __ss_align;	/* Force desired alignment.  */
147e83
     char __ss_padding[_SS_PADSIZE];
147e83
+    __ss_aligntype __ss_align;	/* Force desired alignment.  */
147e83
   };
147e83
 
147e83
 
147e83
diff -rupN a/inet/Makefile b/inet/Makefile
147e83
--- a/inet/Makefile	2017-03-01 16:06:12.000000000 -0500
147e83
+++ b/inet/Makefile	2017-03-01 16:55:21.919485376 -0500
147e83
@@ -51,7 +51,7 @@ aux := check_pf check_native ifreq
147e83
 
147e83
 tests := htontest test_ifindex tst-ntoa tst-ether_aton tst-network \
147e83
 	 tst-gethnm test-ifaddrs bug-if1 test-inet6_opt tst-ether_line \
147e83
-	 tst-getni1 tst-getni2 tst-inet6_rth tst-checks tst-deadline
147e83
+	 tst-getni1 tst-getni2 tst-inet6_rth tst-checks tst-deadline tst-sockaddr
147e83
 
147e83
 # tst-deadline must be linked statically so that we can access
147e83
 # internal functions.
147e83
@@ -89,6 +89,8 @@ CFLAGS-either_hton.c = -fexceptions
147e83
 CFLAGS-getnetgrent.c = -fexceptions
147e83
 CFLAGS-getnetgrent_r.c = -fexceptions
147e83
 
147e83
+CFLAGS-tst-sockaddr.c = -fno-strict-aliasing
147e83
+
147e83
 endif
147e83
 
147e83
 ifeq ($(build-static-nss),yes)
147e83
diff -rupN a/inet/tst-sockaddr.c b/inet/tst-sockaddr.c
147e83
--- a/inet/tst-sockaddr.c	1969-12-31 19:00:00.000000000 -0500
147e83
+++ b/inet/tst-sockaddr.c	2017-03-01 16:38:24.869208278 -0500
147e83
@@ -0,0 +1,125 @@
147e83
+/* Tests for socket address type definitions.
147e83
+   Copyright (C) 2016 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public License as
147e83
+   published by the Free Software Foundation; either version 2.1 of the
147e83
+   License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; see the file COPYING.LIB.  If
147e83
+   not, see <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#include <netinet/in.h>
147e83
+#include <stdbool.h>
147e83
+#include <stddef.h>
147e83
+#include <stdio.h>
147e83
+#include <stdlib.h>
147e83
+#include <string.h>
147e83
+#include <sys/socket.h>
147e83
+#include <sys/un.h>
147e83
+
147e83
+/* This is a copy of the previous definition of struct
147e83
+   sockaddr_storage.  It is not equal to the old value of _SS_SIZE
147e83
+   (128) on all architectures.  We must stay compatible with the old
147e83
+   definition.  */
147e83
+
147e83
+#define OLD_REFERENCE_SIZE 128
147e83
+#define OLD_PADSIZE (OLD_REFERENCE_SIZE - (2 * sizeof (__ss_aligntype)))
147e83
+struct sockaddr_storage_old
147e83
+  {
147e83
+    __SOCKADDR_COMMON (old_);
147e83
+    __ss_aligntype old_align;
147e83
+    char old_padding[OLD_PADSIZE];
147e83
+  };
147e83
+
147e83
+static bool errors;
147e83
+
147e83
+static void
147e83
+check (bool ok, const char *message)
147e83
+{
147e83
+  if (!ok)
147e83
+    {
147e83
+      printf ("error: failed check: %s\n", message);
147e83
+      errors = true;
147e83
+    }
147e83
+}
147e83
+
147e83
+static int
147e83
+do_test (void)
147e83
+{
147e83
+  check (OLD_REFERENCE_SIZE >= _SS_SIZE,
147e83
+         "old target size is not smaller than actual size");
147e83
+  check (sizeof (struct sockaddr_storage_old)
147e83
+         == sizeof (struct sockaddr_storage),
147e83
+         "old and new sizes match");
147e83
+  check (__alignof (struct sockaddr_storage_old)
147e83
+         == __alignof (struct sockaddr_storage),
147e83
+         "old and new alignment matches");
147e83
+  check (offsetof (struct sockaddr_storage_old, old_family)
147e83
+         == offsetof (struct sockaddr_storage, ss_family),
147e83
+         "old and new family offsets match");
147e83
+  check (sizeof (struct sockaddr_storage) == _SS_SIZE,
147e83
+         "struct sockaddr_storage size");
147e83
+
147e83
+  /* Check for lack of holes in the struct definition.   */
147e83
+  check (offsetof (struct sockaddr_storage, __ss_padding)
147e83
+         == __SOCKADDR_COMMON_SIZE,
147e83
+         "implicit padding before explicit padding");
147e83
+  check (offsetof (struct sockaddr_storage, __ss_align)
147e83
+         == __SOCKADDR_COMMON_SIZE
147e83
+           + sizeof (((struct sockaddr_storage) {}).__ss_padding),
147e83
+         "implicit padding before explicit padding");
147e83
+
147e83
+  /* Check for POSIX compatibility requirements between struct
147e83
+     sockaddr_storage and struct sockaddr_un.  */
147e83
+  check (sizeof (struct sockaddr_storage) >= sizeof (struct sockaddr_un),
147e83
+         "sockaddr_storage is at least as large as sockaddr_un");
147e83
+  check (__alignof (struct sockaddr_storage)
147e83
+         >= __alignof (struct sockaddr_un),
147e83
+         "sockaddr_storage is at least as aligned as sockaddr_un");
147e83
+  check (offsetof (struct sockaddr_storage, ss_family)
147e83
+         == offsetof (struct sockaddr_un, sun_family),
147e83
+         "family offsets match");
147e83
+
147e83
+  /* Check that the compiler preserves bit patterns in aggregate
147e83
+     copies.  Based on <https://gcc.gnu.org/PR71120>.  */
147e83
+  check (sizeof (struct sockaddr_storage) >= sizeof (struct sockaddr_in),
147e83
+         "sockaddr_storage is at least as large as sockaddr_in");
147e83
+  {
147e83
+    struct sockaddr_storage addr;
147e83
+    memset (&addr, 0, sizeof (addr));
147e83
+    {
147e83
+      struct sockaddr_in *sinp = (struct sockaddr_in *)&addr;
147e83
+      sinp->sin_family = AF_INET;
147e83
+      sinp->sin_addr.s_addr = htonl (INADDR_LOOPBACK);
147e83
+      sinp->sin_port = htons (80);
147e83
+    }
147e83
+    struct sockaddr_storage copy;
147e83
+    copy = addr;
147e83
+
147e83
+    struct sockaddr_storage *p = malloc (sizeof (*p));
147e83
+    if (p == NULL)
147e83
+      {
147e83
+        printf ("error: malloc: %m\n");
147e83
+        return 1;
147e83
+      }
147e83
+    *p = copy;
147e83
+    const struct sockaddr_in *sinp = (const struct sockaddr_in *)p;
147e83
+    check (sinp->sin_family == AF_INET, "sin_family");
147e83
+    check (sinp->sin_addr.s_addr == htonl (INADDR_LOOPBACK), "sin_addr");
147e83
+    check (sinp->sin_port == htons (80), "sin_port");
147e83
+    free (p);
147e83
+  }
147e83
+
147e83
+  return errors;
147e83
+}
147e83
+
147e83
+#define TEST_FUNCTION do_test ()
147e83
+#include "../test-skeleton.c"
147e83
diff -rupN a/sysdeps/mach/hurd/bits/socket.h b/sysdeps/mach/hurd/bits/socket.h
147e83
--- a/sysdeps/mach/hurd/bits/socket.h	2012-12-24 22:02:13.000000000 -0500
147e83
+++ b/sysdeps/mach/hurd/bits/socket.h	2017-03-01 16:38:24.873208329 -0500
147e83
@@ -156,20 +156,20 @@ struct sockaddr
147e83
 
147e83
 
147e83
 /* Structure large enough to hold any socket address (with the historical
147e83
-   exception of AF_UNIX).  We reserve 128 bytes.  */
147e83
+   exception of AF_UNIX).  */
147e83
 #if ULONG_MAX > 0xffffffff
147e83
 # define __ss_aligntype	__uint64_t
147e83
 #else
147e83
 # define __ss_aligntype	__uint32_t
147e83
 #endif
147e83
-#define _SS_SIZE	128
147e83
-#define _SS_PADSIZE	(_SS_SIZE - (2 * sizeof (__ss_aligntype)))
147e83
+#define _SS_PADSIZE \
147e83
+  (_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype))
147e83
 
147e83
 struct sockaddr_storage
147e83
   {
147e83
     __SOCKADDR_COMMON (ss_);	/* Address family, etc.  */
147e83
-    __ss_aligntype __ss_align;	/* Force desired alignment.  */
147e83
     char __ss_padding[_SS_PADSIZE];
147e83
+    __ss_aligntype __ss_align;	/* Force desired alignment.  */
147e83
   };
147e83
 
147e83
 
147e83
diff -rupN a/sysdeps/unix/bsd/bsd4.4/bits/sockaddr.h b/sysdeps/unix/bsd/bsd4.4/bits/sockaddr.h
147e83
--- a/sysdeps/unix/bsd/bsd4.4/bits/sockaddr.h	2012-12-24 22:02:13.000000000 -0500
147e83
+++ b/sysdeps/unix/bsd/bsd4.4/bits/sockaddr.h	2017-03-01 17:30:34.962261748 -0500
147e83
@@ -37,6 +37,9 @@ typedef unsigned char sa_family_t;
147e83
 
147e83
 #define __SOCKADDR_COMMON_SIZE	(2 * sizeof (unsigned char))
147e83
 
147e83
+/* Size of struct sockaddr_storage.  */
147e83
+#define _SS_SIZE	128
147e83
+
147e83
 #define _HAVE_SA_LEN	1	/* We have the sa_len field.  */
147e83
 
147e83
 #endif	/* bits/sockaddr.h */
147e83
diff -rupN a/sysdeps/unix/bsd/bsd4.4/bits/socket.h b/sysdeps/unix/bsd/bsd4.4/bits/socket.h
147e83
--- a/sysdeps/unix/bsd/bsd4.4/bits/socket.h	2012-12-24 22:02:13.000000000 -0500
147e83
+++ b/sysdeps/unix/bsd/bsd4.4/bits/socket.h	2017-03-01 17:31:23.790246360 -0500
147e83
@@ -142,14 +142,13 @@ struct sockaddr
147e83
 #else
147e83
 # define __ss_aligntype	__uint32_t
147e83
 #endif
147e83
-#define _SS_SIZE	128
147e83
-#define _SS_PADSIZE	(_SS_SIZE - (2 * sizeof (__ss_aligntype)))
147e83
+#define _SS_PADSIZE	(_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype))
147e83
 
147e83
 struct sockaddr_storage
147e83
   {
147e83
     __SOCKADDR_COMMON (ss_);	/* Address family, etc.  */
147e83
-    __ss_aligntype __ss_align;	/* Force desired alignment.  */
147e83
     char __ss_padding[_SS_PADSIZE];
147e83
+    __ss_aligntype __ss_align;	/* Force desired alignment.  */
147e83
   };
147e83
 
147e83
 
147e83
diff -rupN a/sysdeps/unix/sysv/linux/bits/socket.h b/sysdeps/unix/sysv/linux/bits/socket.h
147e83
--- a/sysdeps/unix/sysv/linux/bits/socket.h	2017-03-01 16:06:12.000000000 -0500
147e83
+++ b/sysdeps/unix/sysv/linux/bits/socket.h	2017-03-01 16:38:26.993235460 -0500
147e83
@@ -155,16 +155,16 @@ struct sockaddr
147e83
 
147e83
 
147e83
 /* Structure large enough to hold any socket address (with the historical
147e83
-   exception of AF_UNIX).  We reserve 128 bytes.  */
147e83
+   exception of AF_UNIX).  */
147e83
 #define __ss_aligntype	unsigned long int
147e83
-#define _SS_SIZE	128
147e83
-#define _SS_PADSIZE	(_SS_SIZE - (2 * sizeof (__ss_aligntype)))
147e83
+#define _SS_PADSIZE \
147e83
+  (_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype))
147e83
 
147e83
 struct sockaddr_storage
147e83
   {
147e83
     __SOCKADDR_COMMON (ss_);	/* Address family, etc.  */
147e83
-    __ss_aligntype __ss_align;	/* Force desired alignment.  */
147e83
     char __ss_padding[_SS_PADSIZE];
147e83
+    __ss_aligntype __ss_align;	/* Force desired alignment.  */
147e83
   };
147e83
 
147e83