[PATCH] Make padding in struct sockaddr_storage explicit [BZ #20111]
Florian Weimer
fweimer@redhat.com
Thu May 19 14:37:00 GMT 2016
On 05/19/2016 03:40 PM, Andreas Schwab wrote:
> fweimer@redhat.com (Florian Weimer) writes:
>
>> diff --git a/bits/socket.h b/bits/socket.h
>> index ab9f242..b3f2753 100644
>> --- a/bits/socket.h
>> +++ b/bits/socket.h
>> @@ -164,6 +164,7 @@ struct sockaddr
>> struct sockaddr_storage
>> {
>> __SOCKADDR_COMMON (ss_); /* Address family, etc. */
>> + char __ss_padding_init[sizeof (__ss_aligntype) - __SOCKADDR_COMMON_SIZE];
>
> That needs to be __alignof, otherwise you change the layout, and you
> need to watch out for zero padding.
Hmm. This would have to be conditional on __GNUC__.
What if we put the padding in the middle, like this?
#define _SS_PADSIZE \
_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype)
struct sockaddr_storage
{
__SOCKADDR_COMMON (ss_); /* Address family, etc. */
char __ss_padding[_SS_PADSIZE];
__ss_aligntype __ss_align; /* Force desired alignment. */
};
Then there should be no undeclared padding, and the __ss_align member
should increase the alignment of the entire struct.
Thanks,
Florian
More information about the Libc-alpha
mailing list