[PATCH] QUIC: better sockaddr initialization

Maxim Dounin mdounin at mdounin.ru
Sun May 21 01:42:30 UTC 2023


# 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.

Prodded by Coverity (CID 1530403).

diff --git a/src/event/quic/ngx_event_quic_udp.c b/src/event/quic/ngx_event_quic_udp.c
--- a/src/event/quic/ngx_event_quic_udp.c
+++ b/src/event/quic/ngx_event_quic_udp.c
@@ -183,7 +183,7 @@ ngx_quic_recvmsg(ngx_event_t *ev)
 
             qsock = ngx_quic_get_socket(c);
 
-            ngx_memcpy(&qsock->sockaddr.sockaddr, sockaddr, socklen);
+            ngx_memcpy(&qsock->sockaddr, sockaddr, socklen);
             qsock->socklen = socklen;
 
             c->udp->buffer = &buf;


More information about the nginx-devel mailing list