This issue was discoevered while I was testing SSL_new_from_listener()
using a newly created unit test. It has turned out the QUIC stack
at few places contain pattern as follows:
foo(QUIC_WHATEVER *q, BIO_ADDR *a)
{
q->a = *a;
}
The problem is that derefencning a that way is risky. If the address `a`
comes from BIO_lookup_ex() it may actually be shorter than sizeof(BIO_ADDR).
Using BIO_ADDR_copy() is the right thing to do here.
Fixes #26241
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/26252)
(cherry picked from commit
395a83a617a09c1ae02e8040386f9acb356d13c1)
*/
int BIO_ADDR_make(BIO_ADDR *ap, const struct sockaddr *sa)
{
+ memset(ap, 0, sizeof(BIO_ADDR));
if (sa->sa_family == AF_INET) {
memcpy(&(ap->s_in), sa, sizeof(struct sockaddr_in));
return 1;
if (!ch->addressed_mode)
return 0;
- *peer_addr = ch->cur_peer_addr;
- return 1;
+ return BIO_ADDR_copy(peer_addr, &ch->cur_peer_addr);
}
int ossl_quic_channel_set_peer_addr(QUIC_CHANNEL *ch, const BIO_ADDR *peer_addr)
return 1;
}
- ch->cur_peer_addr = *peer_addr;
- ch->addressed_mode = 1;
+ if (!BIO_ADDR_copy(&ch->cur_peer_addr, peer_addr)) {
+ ch->addressed_mode = 0;
+ return 0;
+ }
+ ch->addressed_mode = 1;
+
return 1;
}
return 0;
/* Note our newly learnt peer address and CIDs. */
- ch->cur_peer_addr = *peer;
+ if (!BIO_ADDR_copy(&ch->cur_peer_addr, peer))
+ return 0;
+
ch->init_dcid = *peer_dcid;
ch->cur_remote_dcid = *peer_scid;
if (!was_coalescing) {
/* Set addresses in TXE. */
- if (pkt->peer != NULL)
- txe->peer = *pkt->peer;
- else
+ if (pkt->peer != NULL) {
+ if (!BIO_ADDR_copy(&txe->peer, pkt->peer))
+ return 0;
+ } else {
BIO_ADDR_clear(&txe->peer);
+ }
- if (pkt->local != NULL)
- txe->local = *pkt->local;
- else
+ if (pkt->local != NULL) {
+ if (!BIO_ADDR_copy(&txe->local, pkt->local))
+ return 0;
+ } else {
BIO_ADDR_clear(&txe->local);
+ }
}
ret = qtx_mutate_write(qtx, pkt, txe, enc_level);
return 1;
}
- txp->args.peer = *peer;
- return 1;
+ return BIO_ADDR_copy(&txp->args.peer, peer);
}
void ossl_quic_tx_packetiser_set_ack_tx_cb(OSSL_QUIC_TX_PACKETISER *txp,