sockaddr.3type: Document that sockaddr_storage is the API to be used
PATCH 1/1 sockaddr.3type: Document that sockaddr_storage is the API to be used
POSIX.1 Issue 8 will fix the long-standing issue with sockaddr APIs, which inevitably caused UB either on user code, libc, or more likely, both. sockaddr_storage has been clarified to be implemented in a manner that aliasing it is safe (suggesting a unnamed union, or other compiler magic).
---
Hi all,
This is my proposal for documenting the POSIX decission of fixing the definition of sockaddr_storage. Bastien, I believe you had something similar in mind; please review. Eric, thanks again for the fix! Could you please also have a look at this?
Cheers,
Alex
man3type/sockaddr.3type | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
man3type/sockaddr.3type +22 -0
@@ -23,6 +23,14 @@ .SH SYNOPSIS .PP .B struct sockaddr_storage { .BR " sa_family_t ss_family;" " /* Address family */" +.PP +.RS 4 +/* This structure is not really implemented this way. It may be +\& implemented with an unnamed union or some compiler magic to +\& avoid breaking aliasing rules when accessed as any other of the +\& sockaddr_* structures documented in this page. See CAVEATS. +\& */ +.RE .B }; .PP .BR typedef " /* ... */ " socklen_t;
@@ -122,6 +130,20 @@ .SH NOTES .I <netinet/in.h> and .IR <sys/un.h> . +.SH CAVEATS +To avoid breaking aliasing rules, +programs that use functions that receive pointers to +.I sockaddr +structures should declare objects of type +.IR sockaddr_storage , +which is defined in a way that it +can be accessed as any of the different structures defined in this page. +Failure to do so may result in Undefined Behavior. +.PP +New functions should be written to accept pointers to +.I sockaddr_storage +instead of the traditional +.IR sockaddr . .SH SEE ALSO .BR accept (2), .BR bind (2),
Signature · 1 line
2.39.2
Quoted 44 lines · Alejandro Colomar
POSIX.1 Issue 8 will fix the long-standing issue with sockaddr APIs, which inevitably caused UB either on user code, libc, or more likely, both.
sockaddr_storagehas been clarified to be implemented in a manner that aliasing it is safe (suggesting a unnamed union, or other compiler magic).Reported-by Bastien Roucariès <[email protected]>Reported-by Alejandro Colomar <[email protected]>Cc glibc <[email protected]>Cc GCC <[email protected]>Cc Eric Blake <[email protected]>Cc Stefan Puiu <[email protected]>Cc Igor Sysoev <[email protected]>Cc Rich Felker <[email protected]>Cc Andrew Clayton <[email protected]>Cc Richard Biener <[email protected]>Cc Zack Weinberg <[email protected]>Cc Florian Weimer <[email protected]>Cc Joseph Myers <[email protected]>Cc Jakub Jelinek <[email protected]>Cc Sam James <[email protected]>Signed-off-by Alejandro Colomar <[email protected]>---
Hi all,
This is my proposal for documenting the POSIX decission of fixing the definition of
sockaddr_storage. Bastien, I believe you had something similar in mind; please review. Eric, thanks again for the fix! Could you please also have a look at this?Cheers,
Alex
man3type/sockaddr.3type | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)man3type/sockaddr.3type +0
-0
man3type/sockaddr.3type .SH SYNOPSIS · line 32
Quoted 10 lines
man3type/sockaddr.3type +7
-0@@ -23,6 +23,14 @@ .SH SYNOPSIS .PP .B struct sockaddr_storage { .BR " sa_family_t ss_family;" " /* Address family */" +.PP +.RS 4 +/* This structure is not really implemented this way. It may be +\& implemented with an unnamed union or some compiler magic to +\& avoid breaking aliasing rules when accessed as any other of the +\& sockaddr_* structures documented in this page. See CAVEATS. +\& */
Do we want similar comments in struct sockaddr and/or sockaddr_XX?
Quoted 7 lines
man3type/sockaddr.3type +1
-0+.RE .B }; .PP .BR typedef " /* ... */ " socklen_t;@@ -122,6 +130,20 @@ .SH NOTES .I <netinet/in.h> and
man3type/sockaddr.3type .SH NOTES · line 141
Quoted 10 lines
man3type/sockaddr.3type +9
-0.IR <sys/un.h> . +.SH CAVEATS +To avoid breaking aliasing rules, +programs that use functions that receive pointers to +.I sockaddr +structures should declare objects of type +.IR sockaddr_storage , +which is defined in a way that it +can be accessed as any of the different structures defined in this page. +Failure to do so may result in Undefined Behavior.
Existing POSIX already requires sockaddr_storage to be suitably sized and aligned to overlay with all other sockaddr* types. What the recent POSIX bug change does is add wording to emphasize that casts in any of the 6 directions:
sockaddr* <-> sockaddr_XX*
sockaddr_storage* <-> sockaddr*
sockaddr_storage* <-> sockaddr_XX*
must allow the sa_family/ss_family/sa_family_t member to overlay without triggering undefined behavior due to bad aliasing, at which point, access to that member lets you deduce what other object type you really have. But you are also correct that merely casting a pointer to another larger struct that doesn't trigger aliasing, but then dereferencing beyond the bounds of the original, is not intended to be portable. The aliasing diagnostics are suppressed because of the requirements on the first member, so now the user must now be careful that their access of remaining members is safe even if the compiler is no longer helping them because of the magic that suppressed the aliasing detection.
I agree with your warning that code that can handle generic socket types should use sockaddr_storage (and not sockaddr) as the original object (the one object that the standard requires to be suitably sized and aligned to overlay with the entirety of all other sockaddr types, rather than just the sa_family_t first member), although we may want to be more precise that code using a specific protocol type can directly use the proper sockaddr_XX type rather than having to use an intermediate sockaddr_storage.
I'm not sure if there are better ways to word that paragraph to convey the intended sentiment.
man3type/sockaddr.3type .SH NOTES · line 146
Quoted 5 lines
man3type/sockaddr.3type +5
-0+.PP +New functions should be written to accept pointers to +.I sockaddr_storage +instead of the traditional +.IR sockaddr .
I'm less certain about this one. The POSIX wording specifically chose to keep existing API/ABI of sockaddr* in all the standardized functions unchanged, as it would be too invasive to existing code to change the signatures now. The burden is on the system headers to define types so that the necessary casts (present in lots of existing code because sockaddr* has a bit more type-safety than void*) do not of themselves cause aliasing issues, and therefore avoid undefined behavior provided subsequent code accessing through the pointers is not accessing beyond the bounds of the real object. The likelihood of POSIX adding new socket APIs taking sockaddr_storage* just to enforce non-aliasing seems slim. But then again, this advice applies to more than just functions likely to be standardized in a future libc, so maybe this paragraph is worth it after all.
Quoted 6 lines
man3type/sockaddr.3type +0
-0.SH SEE ALSO .BR accept (2), .BR bind (2),Signature · 1 line
2.39.2
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Hi Eric,
I'm going to reply both your emails here so that GCC is CCed, and they can suggest better stuff. I'm worried about sending something to POSIX without enough eyes checking it. So this will be a long email.
Quoted 5 lines · eblake
Quoted 4 lines · Alejandro Colomar
Hi Eric!
Quoted 1 line · On 3/30/23 17:22, Austin Group Bug Tracker via austin-group-l at The Open…
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
The following issue has been RESOLVED.
======================================================================
https://austingroupbugs.net/view.php?id=1641...
Quoted 2 lines
Thanks for taking care of this bug!
My pleasure.
:-)
Quoted 32 lines
Quoted 14 lines · On 3/30/23 17:20, Austin Group Bug Tracker via austin-group-l at The Open…
Quoted 7 lines
On page 386 line 13115 section <
sys/socket.h> DESCRIPTION, change:When a pointer to a
sockaddr_storagestructure is cast as a pointer to a sockaddr structure, thess_familyfield of thesockaddr_storagestructure shall map onto thesa_familyfield of the sockaddr structure. When a pointer to asockaddr_storagestructure is cast as a pointer to a protocol-specific address structure, thess_familyfield shall map onto a field of that structure that is of typesa_family_tand that identifies the protocol’s address family.to:
When a pointer to a
sockaddr_storagestructure is cast as a pointer to a sockaddr structure, or vice versa, thess_familyfield of thesockaddr_storagestructure shall map onto thesa_familyfield of the sockaddr structure. When a pointer to asockaddr_storagestructure is cast as a pointer to a protocol-specific address structure, or vice versa, thess_familyfield shall map onto a field of that structure that is of typesa_family_tand that identifies the protocol’s address family. When a pointer to a sockaddr structure is cast as a pointer to a protocol-specific address structure, or vice versa, thesa_familyfield shall map onto a field of that structure that is of typesa_family_tand that identifies the protocol’s address family. Additionally, the structures shall be defined in such a way that these casts do not cause the compiler to produce diagnostics about aliasing issues when compiling conforming application (xref to XBD section 2.2) source files.I will add a CAVEATS section in sockaddr(3type) covering this, and will CC you just to check.
Sure, I'll be happy to review.
The intent from the meeting (and perhaps requires a bit of reading between the lines compared to what was captured as the approved text) was that implementations MUST ensure that existing code does not get miscompiled under the guise of undefined behavior, but without stating how to do it other than suggesting that implementation-specific extensions may be needed (somewhat similar as how POSIX requires that when
dlsym()returns a void* for a function entry point, converting that pointer to a function pointer that can then be called MUST be compiled to work as intended, even though C doesn't define it). We want the burden to be on the libc and system header providers to guarantee defined behavior, and not on the average coder to make careful use ofmemcpy()between storage of different effective types to avoid what might be otherwise undefined if it were written using types declared using only C99 syntax.
Quoted 8 lines
Whether gcc already has all the attributes you need is not my area of expertise. In my skim of the glibc list conversation, I saw mention of attribute [[gnu:transparent_union]] rather than [[
__may_alias__]] - if that's a better implementation-defined extension that does what we need, then use it. The standard developers were a bit uncomfortable directly putting [[gnu:transparent_union]] in the standard, but [[__may_alias__]] was noncontroversial (it's in the namespace reserved for the implementation)
Not really; implementation-defined attributes are required to use an implementation-defined prefix like 'gnu::'. So [[__may_alias__]] is reserved by ISO C, AFAIR. Maybe it would be better to just mention attributes without any specific attribute name; being fuzzy about it would help avoid making promises that we can't hold.
Quoted 24 lines
and deemed to be a sufficient hint for
developers to figure out that they can use whatever works best to meet the actual requirement of not letting the compiler optimize away socket operations under the premise of undefined behavior.Quoted 12 lines
Quoted 10 lines
On page 390 line 13260 section <
sys/socket.h> APPLICATION USAGE, append a sentence:Note that this example only deals with size and alignment; see RATIONALE for additional issues related to these structures.
On page 390 line 13291 section <
sys/socket.h>, change RATIONALE from "None" to:Note that defining the
sockaddr_storageand sockaddr structures using only mechanisms defined in editions of the ISO C standard prior to the 2011 edition (C11) may produce aliasing diagnostics when used in C11 and later editions of the ISO C standard. Because of the large body of existing code utilizing sockets in a way that was well-defined in the 1999 edition of the ISO C standard (C99) but could trigger undefined behavior if C11/C17 aliasing detection were enforced, this standard mandates that casts between pointers to the various socket address structures do not produce aliasing diagnostics, so as to preserve well-defined semantics. An implementation's header files may need to use anonymous unions, or even an implementation-specific extension such as a <tt>[[__may_alias__]]</tt> attribute, to comply with the requirements of this standard.Quoted 6 lines
I'm not sure how aliasing rules changed from C99 to C11. Wasn't aliasing already in C99 (and also in C89)? I believe this was covered by 6.5.7, which is the same in both C99 and C11.
<https://port70.net/~nsz/c/c11/n1570.html#6.5p7>
<https://port70.net/~nsz/c/c99/n1256.html#6.5p7>
Quoted 8 lines
I'm also not sure about where the requirements started making things undefined behavior. I do recall Nick Stoughton mentioning that he seems to remember 'restrict' behavior changing between C99 and C11, so maybe that's why he assumed that C99 permits the behavior without undefined behvaior; but reading
https://port70.net/~nsz/c/c11/n1570.html#Foreword I don't see anything along those lines in C11 that wasn't in C99. It does mention that anonymous unions are new to C11; the Austin Group was unsure whether
Oh, I just learned that anonymous unions are in C11. I thought they were GNU extensions. Nice to know.
Quoted 5 lines
anonymous unions are sufficent to solve the problem on their own (without also causing namespace pollution issues), or if an implementation-defined extension is needed. And maybe compilers got better at alias detection because of the introduction of anonymous unions.
I'm not sure either.
Quoted 9 lines
At any rate, since you did demonstrate that the C11 and C99 wording is essentially the same, I'm happy to forward any alternative wording corrections you propose, and I can bring the topic back up in next week's meeting (if we decide that C99 indeed has undefined behavior, rather than our assumption that it wasn't undefined until C11, we may need to issue an interpretation against Issue 7, rather than just tweaking the wording for Issue 8 when we swap over to C17 as the mandated baseline).
I would just make it more fuzzy about which standard version did what. How about this?:
[[
Note that defining the sockaddr_storage and sockaddr structures using only mechanisms defined in editions of the ISO C standard may produce aliasing diagnostics. Because of the large body of existing code utilizing sockets in a way that could trigger undefined behavior due to strict aliasing rules, this standard mandates that the various socket address structures can alias each other for accessing their first member, so as to preserve well-defined semantics. An implementation's header files may need to use anonymous unions, or even an implementation-specific extension to comply with the requirements of this standard.
]]
Quoted 15 lines
And since both C99 and C11 state that accessing the stored value of an object is permissible through
"a type compatible with the effective type of the object,"
it seems like the obvious action in glibc is to do whatever it takes to convince the compiler that struct sockaddr, struct
sockaddr_storage, and all of the individualsockaddr_XXprotocol types are marked with whatever magic that lets the compiler know that they are compatible types (not necessarily according to the C rules of compatible types, but according to the rules of the extension attribute). I don't know if glibc can do it in isolation, or if gcc will need to invent yet another compiler attribute for glibc's use.
Signature · 2 lines
<http://www.alejandro-colomar.es/> GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
Quoted 49 lines · Eric Blake
Quoted 48 lines · Alejandro Colomar
POSIX.1 Issue 8 will fix the long-standing issue with sockaddr APIs, which inevitably caused UB either on user code, libc, or more likely, both.
sockaddr_storagehas been clarified to be implemented in a manner that aliasing it is safe (suggesting a unnamed union, or other compiler magic).Reported-by Bastien Roucariès <[email protected]>Reported-by Alejandro Colomar <[email protected]>Cc glibc <[email protected]>Cc GCC <[email protected]>Cc Eric Blake <[email protected]>Cc Stefan Puiu <[email protected]>Cc Igor Sysoev <[email protected]>Cc Rich Felker <[email protected]>Cc Andrew Clayton <[email protected]>Cc Richard Biener <[email protected]>Cc Zack Weinberg <[email protected]>Cc Florian Weimer <[email protected]>Cc Joseph Myers <[email protected]>Cc Jakub Jelinek <[email protected]>Cc Sam James <[email protected]>Signed-off-by Alejandro Colomar <[email protected]>---
Hi all,
This is my proposal for documenting the POSIX decission of fixing the definition of
sockaddr_storage. Bastien, I believe you had something similar in mind; please review. Eric, thanks again for the fix! Could you please also have a look at this?Cheers,
Alex
man3type/sockaddr.3type | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)man3type/sockaddr.3type +1
-0@@ -23,6 +23,14 @@ .SH SYNOPSIS .PP .B struct sockaddr_storage { .BR " sa_family_t ss_family;" " /* Address family */" +.PP
Quoted 8 lines
man3type/sockaddr.3type .SH SYNOPSIS · line 32
Quoted 6 lines
man3type/sockaddr.3type +6
-0+.RS 4 +/* This structure is not really implemented this way. It may be +\& implemented with an unnamed union or some compiler magic to +\& avoid breaking aliasing rules when accessed as any other of the +\& sockaddr_* structures documented in this page. See CAVEATS. +\& */Do we want similar comments in struct sockaddr and/or
sockaddr_XX?
I had understood the POSIX change differently. Considering your explanation below, I'll move this to a general NOTES section that applies to all structures.
Quoted 13 lines
Quoted 13 lines
man3type/sockaddr.3type +5
-0+.RE .B }; .PP .BR typedef " /* ... */ " socklen_t;@@ -122,6 +130,20 @@ .SH NOTES .I <netinet/in.h> and .IR <sys/un.h> . +.SH CAVEATS +To avoid breaking aliasing rules, +programs that use functions that receive pointers to +.I sockaddr
Quoted 8 lines
man3type/sockaddr.3type .SH NOTES · line 141
Quoted 5 lines
man3type/sockaddr.3type +5
-0+structures should declare objects of type +.IR sockaddr_storage , +which is defined in a way that it +can be accessed as any of the different structures defined in this page. +Failure to do so may result in Undefined Behavior.Existing POSIX already requires
sockaddr_storageto be suitably sized and aligned to overlay with all other sockaddr* types.
Alignment allows the pointers to be converted to each other and back, but for being able to dereference (access) the pointer, you need stronger guarantees; basically a veto from the standard to strict aliasing rules, as the new wording does.
Quoted 7 lines
What the
recent POSIX bug change does is add wording to emphasize that casts in any of the 6 directions:sockaddr* <-> sockaddr_XX*
sockaddr_storage* <-> sockaddr*
sockaddr_storage* <-> sockaddr_XX*
Hmm, okay. I guess this still doesn't intend to allow traveling this way:
sockaddr_XX <-> sockaddr_storage <-> sockaddr_YY
Not even for checking the first common member, right? Just to be sure of the intention.
Quoted 12 lines
must allow the sa_family/ss_family/sa_family_t member to overlay without triggering undefined behavior due to bad aliasing, at which point, access to that member lets you deduce what other object type you really have. But you are also correct that merely casting a pointer to another larger struct that doesn't trigger aliasing, but then dereferencing beyond the bounds of the original, is not intended to be portable. The aliasing diagnostics are suppressed because of the requirements on the first member, so now the user must now be careful that their access of remaining members is safe even if the compiler is no longer helping them because of the magic that suppressed the aliasing detection.
Yep, I was worried about completely disabling aliasing rules for this reason: we're effectively telling compilers and static analyzers that this is not the droid they're looking for. Hopefully, checking the first field is so simple that no program should forget to do it.
If there's fear that this is a problem, we could maybe allow a smaller set of conversions.
Quoted 9 lines
I agree with your warning that code that can handle generic socket types should use
sockaddr_storage(and not sockaddr) as the original object (the one object that the standard requires to be suitably sized and aligned to overlay with the entirety of all other sockaddr types, rather than just thesa_family_tfirst member), although we may want to be more precise that code using a specific protocol type can directly use the propersockaddr_XXtype rather than having to use an intermediatesockaddr_storage.
It seems reasonable, since it might be an unacceptable overhead if you declare many such objects, and want your program to stay low on memory. Using the smallest structure possible may be important to some programs.
Quoted 15 lines
I'm not sure if there are better ways to word that paragraph to convey the intended sentiment.
man3type/sockaddr.3type .SH NOTES · line 146
Quoted 5 lines
man3type/sockaddr.3type +5
-0+.PP +New functions should be written to accept pointers to +.I sockaddr_storage +instead of the traditional +.IR sockaddr .I'm less certain about this one. The POSIX wording specifically chose to keep existing API/ABI of sockaddr* in all the standardized functions unchanged, as it would be too invasive to existing code to change the signatures now. The burden is on the system headers to define types so that the necessary casts (present in lots of existing
Quoted 8 lines
code because sockaddr* has a bit more type-safety than void*) do not of themselves cause aliasing issues, and therefore avoid undefined behavior provided subsequent code accessing through the pointers is not accessing beyond the bounds of the real object. The likelihood of POSIX adding new socket APIs taking sockaddr_storage* just to enforce non-aliasing seems slim. But then again, this advice applies to more than just functions likely to be standardized in a future libc, so maybe this paragraph is worth it after all.
Depending on your answers to my answers above, I think I agree with you on this.
Cheers,
Alex
Quoted 8 lines
Quoted 7 lines
man3type/sockaddr.3type +0
-0.SH SEE ALSO .BR accept (2), .BR bind (2),Signature · 1 line
2.39.2
Signature · 2 lines
<http://www.alejandro-colomar.es/> GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
Quoted 5 lines · Alejandro Colomar
Hi Eric,
I'm going to reply both your emails here so that GCC is CCed, and they can suggest better stuff. I'm worried about sending something to POSIX without enough eyes checking it. So this will be a long email.
Because your mail landed in a publicly archived mailing list, the POSIX folks saw it anyways ;)
...
Quoted 10 lines
Quoted 9 lines
Whether gcc already has all the attributes you need is not my area of expertise. In my skim of the glibc list conversation, I saw mention of attribute [[gnu:transparent_union]] rather than [[
__may_alias__]] - if that's a better implementation-defined extension that does what we need, then use it. The standard developers were a bit uncomfortable directly putting [[gnu:transparent_union]] in the standard, but [[__may_alias__]] was noncontroversial (it's in the namespace reserved for the implementation)
Quoted 5 lines
Not really; implementation-defined attributes are required to use an implementation-defined prefix like 'gnu::'. So [[
__may_alias__]] is reserved by ISO C, AFAIR. Maybe it would be better to just mention attributes without any specific attribute name; being fuzzy about it would help avoid making promises that we can't hold.
On this point, the group agreed, and we intentionally loosened to wording to just mention an implementation-defined extension, rather than giving any specific attribute name.
...
Quoted 11 lines
I would just make it more fuzzy about which standard version did what. How about this?:
[[
Note that defining thesockaddr_storageand sockaddr structures using only mechanisms defined in editions of the ISO C standard may produce aliasing diagnostics. Because of the large body of existing code utilizing sockets in a way that could trigger undefined behavior due to strict aliasing rules, this standard mandates that the various socket address structures can alias each other for accessing their first member,
The sa_family_t member is not necessarily the first member on all platforms (it happens to be first in Linux, but as a counter-example,
https://man.freebsd.org/cgi/man.cgi?query=unix&sektion=4 shows sun_family as the second one-byte field in struct sockaddr_un). The emphasis is on derefencing the family member (whatever offset it is at) to learn what cast to use to then safely access the rest of the storage.
As such, here's the updated wording that the Austin Group tried today (and we plan on starting a 30-day interpretation feedback window if there are still adjustments to be made to the POSIX wording):
https://austingroupbugs.net/view.php?id=1641#c6255
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Hi Eric,
Quoted 9 lines · Eric Blake
Quoted 5 lines · Alejandro Colomar
Hi Eric,
I'm going to reply both your emails here so that GCC is CCed, and they can suggest better stuff. I'm worried about sending something to POSIX without enough eyes checking it. So this will be a long email.
Because your mail landed in a publicly archived mailing list, the POSIX folks saw it anyways ;)
:)
Quoted 43 lines
...
Quoted 10 lines
Quoted 9 lines
Whether gcc already has all the attributes you need is not my area of expertise. In my skim of the glibc list conversation, I saw mention of attribute [[gnu:transparent_union]] rather than [[
__may_alias__]] - if that's a better implementation-defined extension that does what we need, then use it. The standard developers were a bit uncomfortable directly putting [[gnu:transparent_union]] in the standard, but [[__may_alias__]] was noncontroversial (it's in the namespace reserved for the implementation)Quoted 5 lines
Not really; implementation-defined attributes are required to use an implementation-defined prefix like 'gnu::'. So [[
__may_alias__]] is reserved by ISO C, AFAIR. Maybe it would be better to just mention attributes without any specific attribute name; being fuzzy about it would help avoid making promises that we can't hold.On this point, the group agreed, and we intentionally loosened to wording to just mention an implementation-defined extension, rather than giving any specific attribute name.
...
Quoted 11 lines
I would just make it more fuzzy about which standard version did what. How about this?:
[[
Note that defining thesockaddr_storageand sockaddr structures using only mechanisms defined in editions of the ISO C standard may produce aliasing diagnostics. Because of the large body of existing code utilizing sockets in a way that could trigger undefined behavior due to strict aliasing rules, this standard mandates that the various socket address structures can alias each other for accessing their first member,The
sa_family_tmember is not necessarily the first member on all platforms (it happens to be first in Linux, but as a counter-example,
https://man.freebsd.org/cgi/man.cgi?query=unix&sektion=4 showssun_familyas the second one-byte field in structsockaddr_un). The emphasis is on derefencing the family member (whatever offset it is at) to learn what cast to use to then safely access the rest of the storage.
Quoted 5 lines
As such, here's the updated wording that the Austin Group tried today (and we plan on starting a 30-day interpretation feedback window if there are still adjustments to be made to the POSIX wording):
Thanks! That wording (both paragraphs) LGTM.
Cheers,
Alex
Signature · 2 lines
<http://www.alejandro-colomar.es/> GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5