From bd3cf10270cf68ded80e0555f798961edffc7008 Mon Sep 17 00:00:00 2001 From: Mattia Moffa Date: Wed, 15 Apr 2026 12:39:49 +0200 Subject: [PATCH] DTLS export: cap IV size at buffer size ExportKeyState was writing ssl->specs.iv_size bytes from keys->aead_enc_imp_IV (always sized AEAD_MAX_IMP_SZ). ssl->specs.iv_size carries a different meaning depending on the cipher suite: in AEAD suites it's the implicit IV / nonce size, but in CBC it's the block cipher's IV size (16). In CBC this overran the size of aead_enc_imp_IV (12). --- src/internal.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/internal.c b/src/internal.c index a061851669..7b2ee5c528 100644 --- a/src/internal.c +++ b/src/internal.c @@ -1000,7 +1000,9 @@ static int ExportKeyState(WOLFSSL* ssl, byte* exp, word32 len, byte ver, XMEMCPY(exp + idx, keys->aead_exp_IV, AEAD_MAX_EXP_SZ); idx += AEAD_MAX_EXP_SZ; - sz = (small)? 0: ssl->specs.iv_size; + sz = (small) ? 0 : + (ssl->specs.iv_size > AEAD_MAX_IMP_SZ ? AEAD_MAX_IMP_SZ + : ssl->specs.iv_size); if (idx + (sz * 2) + OPAQUE8_LEN > len) { WOLFSSL_MSG("Buffer not large enough for imp IVs"); return BUFFER_E;