1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
From 1e6fc0b690191005a49468c296ad49d0caacacf1 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Thu, 9 Jun 2016 13:42:06 -0400
Subject: [PATCH] avoid padding gaps in struct sockaddr_storage
compilers are free not to copy, or in some cases to clobber, padding
bytes in a structure. while it's an aliasing violation, and thus
undefined behavior, to copy or manipulate other sockaddr types using
sockaddr_storage, it seems likely that traditional code attempts to do
so, and the original intent of the sockaddr_storage structure was
probably to allow such usage.
in the interest of avoiding silent and potentially dangerous breakage,
ensure that there are no actual padding bytes in sockaddr_storage by
moving and adjusting the size of the __ss_padding member so that it
fits exactly.
this change also removes a silent assumption that the alignment of
long is equal to its size.
---
include/sys/socket.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/sys/socket.h b/include/sys/socket.h
index 76fbde0..55e53d2 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -306,8 +306,8 @@ struct sockaddr
struct sockaddr_storage
{
sa_family_t ss_family;
+ char __ss_padding[128-sizeof(long)-sizeof(sa_family_t)];
unsigned long __ss_align;
- char __ss_padding[128-2*sizeof(unsigned long)];
};
int socket (int, int, int);
--
2.9.1
|