Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use proper ref count handling when adding to x509 store #8233

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions src/x509_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -1102,11 +1102,9 @@ WOLFSSL_X509_STORE* wolfSSL_X509_STORE_new(void)
if ((store->owned = wolfSSL_sk_X509_new_null()) == NULL)
goto err_exit;

#if !defined(WOLFSSL_SIGNER_DER_CERT)
if ((store->trusted = wolfSSL_sk_X509_new_null()) == NULL)
goto err_exit;
#endif
#endif

#ifdef HAVE_CRL
store->crl = store->cm->crl;
Expand Down Expand Up @@ -1196,20 +1194,18 @@ void wolfSSL_X509_STORE_free(WOLFSSL_X509_STORE* store)
}
#if defined(OPENSSL_EXTRA)
if (store->certs != NULL) {
wolfSSL_sk_X509_free(store->certs);
wolfSSL_sk_X509_pop_free(store->certs, NULL);
store->certs = NULL;
}
if (store->owned != NULL) {
wolfSSL_sk_X509_pop_free(store->owned, wolfSSL_X509_free);
wolfSSL_sk_X509_pop_free(store->owned, NULL);
store->owned = NULL;
}
#if !defined(WOLFSSL_SIGNER_DER_CERT)
if (store->trusted != NULL) {
wolfSSL_sk_X509_free(store->trusted);
wolfSSL_sk_X509_pop_free(store->trusted, NULL);
store->trusted = NULL;
}
#endif
#endif
#ifdef OPENSSL_ALL
if (store->objs != NULL) {
X509StoreFreeObjList(store, store->objs);
Expand Down Expand Up @@ -1406,26 +1402,32 @@ int wolfSSL_X509_STORE_add_cert(WOLFSSL_X509_STORE* store, WOLFSSL_X509* x509)
* CA=TRUE */
if (wolfSSL_X509_NAME_cmp(&x509->issuer, &x509->subject) == 0) {
result = X509StoreAddCa(store, x509, WOLFSSL_USER_CA);
#if !defined(WOLFSSL_SIGNER_DER_CERT)
if (result == WOLFSSL_SUCCESS && store->trusted != NULL) {
result = wolfSSL_sk_X509_push(store->trusted, x509);
if (result > 0) {
result = WOLFSSL_SUCCESS;
}
else {
result = WOLFSSL_FATAL_ERROR;
result = wolfSSL_X509_up_ref(x509);
if (result == WOLFSSL_SUCCESS) {
result = wolfSSL_sk_X509_push(store->trusted, x509);
if (result > 0) {
result = WOLFSSL_SUCCESS;
}
else {
result = WOLFSSL_FATAL_ERROR;
ColtonWilley marked this conversation as resolved.
Show resolved Hide resolved
wolfSSL_X509_free(x509);
}
}
}
#endif
}
else {
if (store->certs != NULL) {
result = wolfSSL_sk_X509_push(store->certs, x509);
if (result > 0) {
result = WOLFSSL_SUCCESS;
}
else {
result = WOLFSSL_FATAL_ERROR;
result = wolfSSL_X509_up_ref(x509);
if (result == WOLFSSL_SUCCESS) {
result = wolfSSL_sk_X509_push(store->certs, x509);
if (result > 0) {
result = WOLFSSL_SUCCESS;
}
else {
result = WOLFSSL_FATAL_ERROR;
wolfSSL_X509_free(x509);
}
}
}
else {
Expand Down
Loading