Skip to content

Commit 1b8254d

Browse files
authored
Merge pull request #7808 from Laboratory-for-Safe-and-Secure-Systems/preTBS_memory_leak
Fix memory leak in wc_GeneratePreTBS()
2 parents 1bc0853 + 36d01cd commit 1b8254d

1 file changed

Lines changed: 0 additions & 14 deletions

File tree

src/x509.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7521,20 +7521,12 @@ int wolfSSL_i2d_X509(WOLFSSL_X509* x509, unsigned char** out)
75217521
int wc_GeneratePreTBS(DecodedCert* cert, byte *der, int derSz) {
75227522
int ret = 0;
75237523
WOLFSSL_X509 *x = NULL;
7524-
byte certOwnsAltNames = 0;
75257524
byte certIsCSR = 0;
75267525

75277526
if ((cert == NULL) || (der == NULL) || (derSz <= 0)) {
75287527
return BAD_FUNC_ARG;
75297528
}
75307529

7531-
/* The call to CopyDecodedToX509() transfers ownership of the altNames in
7532-
* the DecodedCert to the temporary X509 object, causing the list to be
7533-
* freed in wolfSSL_X509_free(). As this is an unintended side-effect, we
7534-
* have to save the ownerFlag here and transfer ownership back to the
7535-
* DecodedCert prior to freeing the X509 object. */
7536-
certOwnsAltNames = cert->weOwnAltNames;
7537-
75387530
#ifdef WOLFSSL_CERT_REQ
75397531
certIsCSR = cert->isCSR;
75407532
#endif
@@ -7547,9 +7539,6 @@ int wc_GeneratePreTBS(DecodedCert* cert, byte *der, int derSz) {
75477539
ret = CopyDecodedToX509(x, cert);
75487540
}
75497541

7550-
/* CopyDecodedToX509() clears cert->weOwnAltNames. Restore it. */
7551-
cert->weOwnAltNames = certOwnsAltNames;
7552-
75537542
if (ret == 0) {
75547543
/* Remove the altsigval extension. */
75557544
XFREE(x->altSigValDer, x->heap, DYNAMIC_TYPE_X509_EXT);
@@ -7565,9 +7554,6 @@ int wc_GeneratePreTBS(DecodedCert* cert, byte *der, int derSz) {
75657554
}
75667555

75677556
if (x != NULL) {
7568-
/* Safe the altNames list from being freed unitentionally. */
7569-
x->altNames = NULL;
7570-
75717557
wolfSSL_X509_free(x);
75727558
}
75737559

0 commit comments

Comments
 (0)