[PATCH] QUIC: better sockaddr initialization
Maxim Dounin
mdounin at mdounin.ru
Sun May 21 13:09:57 UTC 2023
Hello!
On Sun, May 21, 2023 at 11:31:32AM +0200, Alejandro Colomar wrote:
> On 5/21/23 03:42, Maxim Dounin wrote:
> > # HG changeset patch
> > # User Maxim Dounin <mdounin at mdounin.ru>
> > # Date 1684633125 -10800
> > # Sun May 21 04:38:45 2023 +0300
> > # Node ID 68fa4b86ed46138dd1a8fcf2cfd80206de068bec
> > # Parent 235d482ef6bc8c40a956b2413865d42c94e0fc05
> > QUIC: better sockaddr initialization.
> >
> > The qsock->sockaddr field is a ngx_sockaddr_t union, and therefore can hold
> > any sockaddr (and union members, such qsock->sockaddr.sockaddr, can be used
> > to access appropriate variant of the sockaddr). It is better to set it via
> > qsock->sockaddr itself though, and not qsock->sockaddr.sockaddr, so static
> > analyzers won't complain about out-of-bounds access.
>
> Correct. The previous code was UB, due to memcpy(3) writing to the
> 'struct sockaddr' member. By writing to sockaddr, you were only
> allowed to alias via other members the sa_family_t field, but no
> others.
Well, not really. There is no UB in the previous code, it simply
uses a valid (void *) address to fill the sockaddr (and does so
without breaking strict aliasing rules).
But the code might confuse static analyzers, since they have no
way to know that the whole ngx_sockaddr_t is being set, and not
just the (struct sockaddr) union member which is referenced.
--
Maxim Dounin
http://mdounin.ru/
More information about the nginx-devel
mailing list