crl: refactoring BufferLoadCRL to reduce stack usage:

--- variable dcrl moved to the heap (sizeof(DecodedCRL) saved)
This commit is contained in:
Moisés Guimarães
2014-07-14 17:28:08 -03:00
parent fb3e706d69
commit 6e0c6551ff

View File

@@ -243,7 +243,11 @@ int BufferLoadCRL(CYASSL_CRL* crl, const byte* buff, long sz, int type)
int ret = SSL_SUCCESS; int ret = SSL_SUCCESS;
const byte* myBuffer = buff; /* if DER ok, otherwise switch */ const byte* myBuffer = buff; /* if DER ok, otherwise switch */
buffer der; buffer der;
DecodedCRL dcrl; #ifdef CYASSL_SMALL_STACK
DecodedCRL* dcrl;
#else
DecodedCRL dcrl[1];
#endif
der.buffer = NULL; der.buffer = NULL;
@@ -268,25 +272,38 @@ int BufferLoadCRL(CYASSL_CRL* crl, const byte* buff, long sz, int type)
} }
} }
InitDecodedCRL(&dcrl); #ifdef CYASSL_SMALL_STACK
ret = ParseCRL(&dcrl, myBuffer, (word32)sz, crl->cm); 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) { if (ret != 0) {
CYASSL_MSG("ParseCRL error"); CYASSL_MSG("ParseCRL error");
} }
else { else {
ret = AddCRL(crl, &dcrl); ret = AddCRL(crl, dcrl);
if (ret != 0) { if (ret != 0) {
CYASSL_MSG("AddCRL error"); CYASSL_MSG("AddCRL error");
} }
} }
FreeDecodedCRL(&dcrl);
FreeDecodedCRL(dcrl);
#ifdef CYASSL_SMALL_STACK
XFREE(dcrl, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
if (der.buffer) if (der.buffer)
XFREE(der.buffer, NULL, DYNAMIC_TYPE_CRL); XFREE(der.buffer, NULL, DYNAMIC_TYPE_CRL);
if (ret == 0) return ret ? ret : SSL_SUCCESS; /* convert 0 to SSL_SUCCESS */
return SSL_SUCCESS; /* convert */
return ret;
} }