Merge pull request #5437 from douzzer/20220804-fixes

20220804 fixes
This commit is contained in:
David Garske
2022-08-04 13:55:03 -07:00
committed by GitHub
2 changed files with 29 additions and 11 deletions

View File

@ -26227,8 +26227,10 @@ static int SetReqAttribSingle(byte* output, int* idx, char* attr, int attrSz,
if (strSz > 0) { if (strSz > 0) {
XMEMCPY(&output[*idx], str, strSz); XMEMCPY(&output[*idx], str, strSz);
*idx += strSz; *idx += strSz;
XMEMCPY(&output[*idx], attr, attrSz); if (attrSz > 0) {
*idx += attrSz; XMEMCPY(&output[*idx], attr, attrSz);
*idx += attrSz;
}
} }
} }
return totalSz; return totalSz;

View File

@ -1012,18 +1012,25 @@ void wc_FreeCertList(WC_DerCertList* list, void* heap)
(void)heap; (void)heap;
} }
static void freeDecCertList(WC_DerCertList** list, byte** pkey, word32* pkeySz, static WARN_UNUSED_RESULT int freeDecCertList(WC_DerCertList** list,
byte** cert, word32* certSz, void* heap) byte** pkey, word32* pkeySz, byte** cert, word32* certSz, void* heap)
{ {
WC_DerCertList* current = *list; WC_DerCertList* current = *list;
WC_DerCertList* previous = NULL; WC_DerCertList* previous = NULL;
DecodedCert DeCert; #ifdef WOLFSSL_SMALL_STACK
DecodedCert *DeCert = (DecodedCert *)XMALLOC(
sizeof(*DeCert), heap, DYNAMIC_TYPE_PKCS);
if (DeCert == NULL)
return MEMORY_E;
#else
DecodedCert DeCert[1];
#endif
while (current != NULL) { while (current != NULL) {
InitDecodedCert(&DeCert, current->buffer, current->bufferSz, heap); InitDecodedCert(DeCert, current->buffer, current->bufferSz, heap);
if (ParseCertRelative(&DeCert, CERT_TYPE, NO_VERIFY, NULL) == 0) { if (ParseCertRelative(DeCert, CERT_TYPE, NO_VERIFY, NULL) == 0) {
if (wc_CheckPrivateKeyCert(*pkey, *pkeySz, &DeCert) == 1) { if (wc_CheckPrivateKeyCert(*pkey, *pkeySz, DeCert) == 1) {
WOLFSSL_MSG("Key Pair found"); WOLFSSL_MSG("Key Pair found");
*cert = current->buffer; *cert = current->buffer;
*certSz = current->bufferSz; *certSz = current->bufferSz;
@ -1034,16 +1041,22 @@ static void freeDecCertList(WC_DerCertList** list, byte** pkey, word32* pkeySz,
else { else {
previous->next = current->next; previous->next = current->next;
} }
FreeDecodedCert(&DeCert); FreeDecodedCert(DeCert);
XFREE(current, heap, DYNAMIC_TYPE_PKCS); XFREE(current, heap, DYNAMIC_TYPE_PKCS);
break; break;
} }
} }
FreeDecodedCert(&DeCert); FreeDecodedCert(DeCert);
previous = current; previous = current;
current = current->next; current = current->next;
} }
#ifdef WOLFSSL_SMALL_STACK
XFREE(DeCert, heap, DYNAMIC_TYPE_PKCS);
#endif
return 0;
} }
@ -1446,7 +1459,10 @@ int wc_PKCS12_parse(WC_PKCS12* pkcs12, const char* psw,
/* check if key pair, remove from list */ /* check if key pair, remove from list */
if (*pkey != NULL) { if (*pkey != NULL) {
freeDecCertList(&certList, pkey, pkeySz, cert, certSz, pkcs12->heap); ret = freeDecCertList(&certList, pkey, pkeySz, cert, certSz,
pkcs12->heap);
if (ret < 0)
goto exit_pk12par;
} }
/* if ca arg provided return certList, otherwise free it */ /* if ca arg provided return certList, otherwise free it */