For a remote CONNECTION_CLOSE, src->reason points straight into the
received packet and holds exactly reason_len bytes with no guaranteed
trailing byte. copy_tcause() did OPENSSL_memdup(src->reason, l + 1),
reading one byte past the source. The +1 is only needed to make room
for the NUL written at r[l], so allocate l + 1 but copy only the l
valid bytes.
Fixes: 40c8c756c86f "QUIC APL/CHANNEL: Wire up connection closure reason"
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
MergeDate: Wed Jun 3 11:39:47 2026
(Merged from https://github.com/openssl/openssl/pull/31349)
* If this fails, dst->reason becomes NULL and we simply do not use a
* reason. This ensures termination is infallible.
*/
- dst->reason = r = OPENSSL_memdup(src->reason, l + 1);
+ dst->reason = r = OPENSSL_malloc(l + 1);
if (r == NULL)
return;
+ memcpy(r, src->reason, l);
r[l] = '\0';
dst->reason_len = l;
}