From d29c656d4f2b362a0cf993e51acb6956825801a6 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Wed, 1 Jun 2022 16:48:57 +0200 Subject: [PATCH] SendAlert: clear output buffer to try and send the alert now --- src/internal.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/internal.c b/src/internal.c index f78299161..286c26c6f 100644 --- a/src/internal.c +++ b/src/internal.c @@ -20640,8 +20640,25 @@ int SendAlert(WOLFSSL* ssl, int severity, int type) /* check for available size */ outputSz = ALERT_SIZE + MAX_MSG_EXTRA + dtlsExtra; - if ((ret = CheckAvailableSize(ssl, outputSz)) != 0) + if ((ret = CheckAvailableSize(ssl, outputSz)) != 0) { +#ifdef WOLFSSL_DTLS + /* If CheckAvailableSize returned WANT_WRITE due to a blocking write + * then discard pending output and just send the alert. */ + if (ssl->options.dtls) { + if (ret != WANT_WRITE || severity != alert_fatal) + return ret; + ShrinkOutputBuffer(ssl); + if ((ret = CheckAvailableSize(ssl, outputSz)) != 0) { + return ret; + } + } + else { + return ret; + } +#else return ret; +#endif + } /* Check output buffer */ if (ssl->buffers.outputBuffer.buffer == NULL)