public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "eblake at redhat dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug network/30293] Socket API is not alias safe
Date: Fri, 21 Jul 2023 19:52:33 +0000	[thread overview]
Message-ID: <bug-30293-131-ncWIQPdWsK@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-30293-131@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=30293

--- Comment #3 from Eric Blake <eblake at redhat dot com> ---
(In reply to Bastien Roucariès from comment #2)
> Any news now that POSIX was amended ?

Issue 8 is not yet finalized; but the latest POSIX wording looks like it will
be this:
https://austingroupbugs.net/view.php?id=1641#c6290

with the following normative text:
    When a pointer to a sockaddr_storage structure is converted to a pointer to
a sockaddr structure, or vice versa, the ss_family member of the
sockaddr_storage structure shall map onto the sa_family member of the sockaddr
structure. When a pointer to a sockaddr_storage structure is converted to a
pointer to a protocol-specific address structure, or vice versa, the ss_family
member shall map onto a member of that structure that is of type sa_family_t
that identifies the protocol’s address family. When a pointer to a sockaddr
structure is converted to a pointer to a protocol-specific address structure,
or vice versa, the sa_family member shall map onto a member of that structure
that is of type sa_family_t that identifies the protocol’s address family.
Additionally, the structures shall be defined in such a way that the compiler
treats an access to the stored value of the sa_family_t member of any of these
structures, via an lvalue expression whose type involves any other one of these
structures, as permissible, despite the more restrictive expression rules on
stored value access as stated in the ISO C standard. Similarly, when a pointer
to a sockaddr_storage or sockaddr structure is converted to a pointer to a
protocol-specific address structure, the compiler shall treat an access (using
this converted pointer) to the stored value of any member of the
protocol-specific structure as permissible. The application shall ensure that
the protocol-specific address structure corresponds to the family indicated by
the member with type sa_family_t of that structure and the pointed-to object
has sufficient memory for addressing all members of the protocol-specific
structure.

and the following informative rationale text:
Note that defining the sockaddr_storage and sockaddr structures using only
mechanisms defined in early editions of the ISO C standard may produce aliasing
diagnostics when applications use casting between pointers to the various
socket address structures. 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 these structures can alias each other for
accessing the sa_family_t member of the structures (or other members for
protocol-specific structure references), 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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2023-07-21 19:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-30 17:41 [Bug network/30293] New: " rouca at debian dot org
2023-03-30 17:41 ` [Bug network/30293] " rouca at debian dot org
2023-03-30 20:11 ` sam at gentoo dot org
2023-03-30 20:11 ` sam at gentoo dot org
2023-03-30 21:24 ` eblake at redhat dot com
2023-07-21 19:28 ` rouca at debian dot org
2023-07-21 19:52 ` eblake at redhat dot com [this message]
2024-05-07 19:42 ` sam at gentoo dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-30293-131-ncWIQPdWsK@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).