From: Matt Caswell Date: Wed, 26 Oct 2022 16:14:21 +0000 (+0100) Subject: Assert that we do not exceed the DTLS MTU X-Git-Tag: openssl-3.2.0-alpha1~1786 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=351ad225b3758f96a5875eb11ac3acda006a1c00;p=thirdparty%2Fopenssl.git Assert that we do not exceed the DTLS MTU Reviewed-by: Paul Dale Reviewed-by: Hugo Landau (Merged from https://github.com/openssl/openssl/pull/19516) --- diff --git a/ssl/statem/statem_dtls.c b/ssl/statem/statem_dtls.c index 2e71014ef8a..4effc584160 100644 --- a/ssl/statem/statem_dtls.c +++ b/ssl/statem/statem_dtls.c @@ -7,6 +7,7 @@ * https://www.openssl.org/source/license.html */ +#include #include #include #include @@ -255,6 +256,16 @@ int dtls1_do_write(SSL_CONNECTION *s, int type) if (!ossl_assert(len == written)) return -1; + /* + * We should not exceed the MTU size. If compression is in use + * then the max record overhead calculation is unreliable so we do + * not check in that case. We use assert rather than ossl_assert + * because in a production build, if this assert were ever to fail, + * then the best thing to do is probably carry on regardless. + */ + assert(s->s3.tmp.new_compression != NULL + || BIO_wpending(s->wbio) <= (int)s->d1->mtu); + if (type == SSL3_RT_HANDSHAKE && !s->d1->retransmitting) { /* * should not be done for 'Hello Request's, but in that case