From 6e0c6551ffcb17867b8bf19f397726b926d8793f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20Guimar=C3=A3es?= Date: Mon, 14 Jul 2014 17:28:08 -0300 Subject: [PATCH] crl: refactoring BufferLoadCRL to reduce stack usage: --- variable dcrl moved to the heap (sizeof(DecodedCRL) saved) --- src/crl.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/crl.c b/src/crl.c index 9b94aab7b..26a8f8454 100644 --- a/src/crl.c +++ b/src/crl.c @@ -243,7 +243,11 @@ int BufferLoadCRL(CYASSL_CRL* crl, const byte* buff, long sz, int type) int ret = SSL_SUCCESS; const byte* myBuffer = buff; /* if DER ok, otherwise switch */ buffer der; - DecodedCRL dcrl; +#ifdef CYASSL_SMALL_STACK + DecodedCRL* dcrl; +#else + DecodedCRL dcrl[1]; +#endif der.buffer = NULL; @@ -268,25 +272,38 @@ int BufferLoadCRL(CYASSL_CRL* crl, const byte* buff, long sz, int type) } } - InitDecodedCRL(&dcrl); - ret = ParseCRL(&dcrl, myBuffer, (word32)sz, crl->cm); +#ifdef CYASSL_SMALL_STACK + dcrl = (DecodedCRL*)XMALLOC(sizeof(DecodedCRL), NULL, DYNAMIC_TYPE_TMP_BUFFER); + if (dcrl == NULL) { + if (der.buffer) + XFREE(der.buffer, NULL, DYNAMIC_TYPE_CRL); + + return MEMORY_E; + } +#endif + + InitDecodedCRL(dcrl); + ret = ParseCRL(dcrl, myBuffer, (word32)sz, crl->cm); if (ret != 0) { CYASSL_MSG("ParseCRL error"); } else { - ret = AddCRL(crl, &dcrl); + ret = AddCRL(crl, dcrl); if (ret != 0) { CYASSL_MSG("AddCRL error"); } } - FreeDecodedCRL(&dcrl); + + FreeDecodedCRL(dcrl); + +#ifdef CYASSL_SMALL_STACK + XFREE(dcrl, NULL, DYNAMIC_TYPE_TMP_BUFFER); +#endif if (der.buffer) XFREE(der.buffer, NULL, DYNAMIC_TYPE_CRL); - if (ret == 0) - return SSL_SUCCESS; /* convert */ - return ret; + return ret ? ret : SSL_SUCCESS; /* convert 0 to SSL_SUCCESS */ }