From 1929024029d3d789e7daa094d5d599c3d87e43a0 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Sat, 29 May 2021 01:10:30 +0700 Subject: [PATCH] fix for getting export buffer size --- src/internal.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/internal.c b/src/internal.c index 8773a7cd1..9c3049c76 100644 --- a/src/internal.c +++ b/src/internal.c @@ -1836,7 +1836,7 @@ int wolfSSL_session_export_internal(WOLFSSL* ssl, byte* buf, word32* sz, WOLFSSL_ENTER("wolfSSL_session_export_internal"); - if (buf == NULL || ssl == NULL) { + if (ssl == NULL) { WOLFSSL_MSG("unexpected null argument"); ret = BAD_FUNC_ARG; } @@ -1855,8 +1855,8 @@ int wolfSSL_session_export_internal(WOLFSSL* ssl, byte* buf, word32* sz, } /* check is at least the minimum size needed, TLS cipher states add more */ - if (ret == 0 && totalLen > *sz) { - WOLFSSL_MSG("export buffer was too small"); + if (ret == 0 && (totalLen > *sz || buf == NULL)) { + WOLFSSL_MSG("export buffer was too small or null"); *sz = totalLen; /* possible AES state needed */ @@ -1921,7 +1921,7 @@ int wolfSSL_session_export_internal(WOLFSSL* ssl, byte* buf, word32* sz, } } - if (ret != 0) { + if (ret != 0 && buf != NULL) { /*in a fail case clear the buffer which could contain partial key info*/ XMEMSET(buf, 0, *sz); } @@ -1942,6 +1942,10 @@ int wolfSSL_session_export_internal(WOLFSSL* ssl, byte* buf, word32* sz, #endif /* WOLFSSL_SESSION_EXPORT_DEBUG */ } + if (ret >= 0) { + *sz = ret; + } + WOLFSSL_LEAVE("wolfSSL_session_export_internal", ret); return ret; }