Fix wolfSSL_GENERAL_NAMES_free memory leak.

This function was just freeing the stack object itself of GENERAL_NAMES with
wolfSSL_sk_free, but this doesn't free the data in the items of the stack. The
fix is to replace wolfSSL_sk_free with wolfSSL_sk_GENERAL_NAME_free.
This commit is contained in:
Hayden Roche
2022-08-24 18:31:21 -07:00
parent 8268214297
commit 9f39ffdba7
2 changed files with 33 additions and 20 deletions

View File

@@ -4315,7 +4315,7 @@ void wolfSSL_GENERAL_NAMES_free(WOLFSSL_GENERAL_NAMES *gens)
return;
}
wolfSSL_sk_free(gens);
wolfSSL_sk_GENERAL_NAME_free(gens);
}
#if defined(OPENSSL_ALL) && !defined(NO_BIO)

View File

@@ -41511,6 +41511,8 @@ static int test_wolfSSL_sk_GENERAL_NAME(void)
unsigned char buf[4096];
const unsigned char* bufPt;
int bytes, i;
int j;
XFILE f;
STACK_OF(GENERAL_NAME)* sk;
@@ -41521,6 +41523,7 @@ static int test_wolfSSL_sk_GENERAL_NAME(void)
AssertIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
XFCLOSE(f);
for (j = 0; j < 2; ++j) {
bufPt = buf;
AssertNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
@@ -41544,7 +41547,17 @@ static int test_wolfSSL_sk_GENERAL_NAME(void)
}
}
X509_free(x509);
if (j == 0) {
sk_GENERAL_NAME_pop_free(sk, GENERAL_NAME_free);
}
else {
/*
* We had a bug where GENERAL_NAMES_free didn't free all the memory
* it was supposed to. This is a regression test for that bug.
*/
GENERAL_NAMES_free(sk);
}
}
printf(resultFmt, passed);
#endif