diff options
author | Florian Weimer <fweimer@redhat.com> | 2016-05-23 19:43:09 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2016-05-23 19:43:09 +0200 |
commit | 3375cfafa7961c6ae0e509c31c3b3cef9ad1f03d (patch) | |
tree | 0c2ba750f8b7e15a6b826f9767fbb533bfb4f567 /bits | |
parent | d912d3a1198dfa9acd59cb5a07e5ed27c910cb7f (diff) | |
download | glibc-3375cfafa7961c6ae0e509c31c3b3cef9ad1f03d.tar.gz glibc-3375cfafa7961c6ae0e509c31c3b3cef9ad1f03d.tar.xz glibc-3375cfafa7961c6ae0e509c31c3b3cef9ad1f03d.zip |
Make padding in struct sockaddr_storage explicit [BZ #20111]
This avoids aliasing issues with GCC 6 in -fno-strict-aliasing mode. (With implicit padding, not all data is copied.) This change makes it explicit that struct sockaddr_storage is only 126 bytes large on m68k (unlike elsewhere, where we end up with the requested 128 bytes). The new test case makes sure that this does not happen on other architectures.
Diffstat (limited to 'bits')
-rw-r--r-- | bits/sockaddr.h | 5 | ||||
-rw-r--r-- | bits/socket.h | 8 |
2 files changed, 8 insertions, 5 deletions
diff --git a/bits/sockaddr.h b/bits/sockaddr.h index e91f837954..0af58c9ebb 100644 --- a/bits/sockaddr.h +++ b/bits/sockaddr.h @@ -1,4 +1,4 @@ -/* Definition of `struct sockaddr_*' common members. Generic/4.2 BSD version. +/* Definition of struct sockaddr_* common members and sizes, generic version. Copyright (C) 1995-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -36,4 +36,7 @@ typedef unsigned short int sa_family_t; #define __SOCKADDR_COMMON_SIZE (sizeof (unsigned short int)) +/* Size of struct sockaddr_storage. */ +#define _SS_SIZE 128 + #endif /* bits/sockaddr.h */ diff --git a/bits/socket.h b/bits/socket.h index ab9f242cf0..a22fd56031 100644 --- a/bits/socket.h +++ b/bits/socket.h @@ -152,20 +152,20 @@ struct sockaddr /* Structure large enough to hold any socket address (with the historical - exception of AF_UNIX). We reserve 128 bytes. */ + exception of AF_UNIX). */ #if ULONG_MAX > 0xffffffff # define __ss_aligntype __uint64_t #else # define __ss_aligntype __uint32_t #endif -#define _SS_SIZE 128 -#define _SS_PADSIZE (_SS_SIZE - (2 * sizeof (__ss_aligntype))) +#define _SS_PADSIZE \ + (_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype)) struct sockaddr_storage { __SOCKADDR_COMMON (ss_); /* Address family, etc. */ - __ss_aligntype __ss_align; /* Force desired alignment. */ char __ss_padding[_SS_PADSIZE]; + __ss_aligntype __ss_align; /* Force desired alignment. */ }; |