sanity check on pem size

This commit is contained in:
Jacob Barthelmeh
2021-11-19 13:55:03 -07:00
parent ca72beb688
commit 5d49847147

View File

@@ -43032,10 +43032,11 @@ cleanup:
return NULL; return NULL;
} }
pem = (unsigned char*)XMALLOC(l, 0, DYNAMIC_TYPE_PEM); pemSz = (int)l;
pem = (unsigned char*)XMALLOC(pemSz, 0, DYNAMIC_TYPE_PEM);
if (pem == NULL) if (pem == NULL)
return NULL; return NULL;
XMEMSET(pem, 0, l); XMEMSET(pem, 0, pemSz);
i = 0; i = 0;
if (wc_PemGetHeaderFooter(type, NULL, &footer) != 0) { if (wc_PemGetHeaderFooter(type, NULL, &footer) != 0) {
@@ -43069,6 +43070,10 @@ cleanup:
#else #else
(void)l; (void)l;
#endif #endif
if (i > pemSz) {
WOLFSSL_MSG("Error parsing PEM");
}
else {
pemSz = (int)i; pemSz = (int)i;
#ifdef WOLFSSL_CERT_REQ #ifdef WOLFSSL_CERT_REQ
if (type == CERTREQ_TYPE) if (type == CERTREQ_TYPE)
@@ -43078,6 +43083,7 @@ cleanup:
#endif #endif
x509 = wolfSSL_X509_load_certificate_buffer(pem, pemSz, x509 = wolfSSL_X509_load_certificate_buffer(pem, pemSz,
WOLFSSL_FILETYPE_PEM); WOLFSSL_FILETYPE_PEM);
}
if (x != NULL) { if (x != NULL) {
*x = x509; *x = x509;