From 0938a0055d884ed429925c5a057b5fdc7c8e700c Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 12 Feb 2021 15:18:14 +0700 Subject: [PATCH] always use MAX_CHAIN_DEPTH for args->certs buffer --- src/internal.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/internal.c b/src/internal.c index 5687846b6..7f5a4a4cb 100644 --- a/src/internal.c +++ b/src/internal.c @@ -10841,21 +10841,12 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx, #endif /* allocate buffer for certs */ - #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) - args->certs = (buffer*)XMALLOC(sizeof(buffer) * - (ssl->verifyDepth + 1), ssl->heap, DYNAMIC_TYPE_DER); - if (args->certs == NULL) { - ERROR_OUT(MEMORY_E, exit_ppc); - } - XMEMSET(args->certs, 0, sizeof(buffer) * (ssl->verifyDepth + 1)); - #else args->certs = (buffer*)XMALLOC(sizeof(buffer) * MAX_CHAIN_DEPTH, ssl->heap, DYNAMIC_TYPE_DER); if (args->certs == NULL) { ERROR_OUT(MEMORY_E, exit_ppc); } XMEMSET(args->certs, 0, sizeof(buffer) * MAX_CHAIN_DEPTH); - #endif /* OPENSSL_EXTRA */ /* Certificate List */ if ((args->idx - args->begin) + OPAQUE24_LEN > totalSz) { @@ -10878,10 +10869,12 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx, #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) - if (args->totalCerts > ssl->verifyDepth) { + if (args->totalCerts >= MAX_CHAIN_DEPTH) { ssl->peerVerifyRet = X509_V_ERR_CERT_CHAIN_TOO_LONG; ret = MAX_CHAIN_ERROR; - break; /* break out to do certificate verify callback */ + WOLFSSL_MSG("Too many certs for MAX_CHAIN_DEPTH"); + break; /* break out to avoid reading more certs then buffer + * can hold */ } #else if (args->totalCerts >= ssl->verifyDepth || @@ -11122,15 +11115,15 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx, (void)doCrlLookup; } #endif /* HAVE_OCSP || HAVE_CRL */ -#ifdef OPENSSL_EXTRA - if (ret == 0 && - /* extend the limit "+1" until reaching + #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) + if (ret == 0 && + /* extend the limit "+1" until reaching * an ultimately trusted issuer.*/ args->count > (ssl->verifyDepth + 1)) { ssl->peerVerifyRet = X509_V_ERR_CERT_CHAIN_TOO_LONG; ret = MAX_CHAIN_ERROR; } -#endif + #endif /* Do verify callback */ ret = DoVerifyCallback(ssl->ctx->cm, ssl, ret, args); if (ssl->options.verifyNone &&