Skip to content

Commit

Permalink
adjust x509 reference up location for store certs
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBarthelmeh committed Dec 24, 2024
1 parent 3186451 commit 1d09018
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/x509_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -1860,9 +1860,17 @@ WOLF_STACK_OF(WOLFSSL_X509_OBJECT)* wolfSSL_X509_STORE_get0_objects(
}
}
for (i = 0; i < wolfSSL_sk_X509_num(store->certs); i++) {
if (wolfSSL_sk_X509_push(cert_stack,
wolfSSL_sk_X509_value(store->certs, i)) > 0) {
x509 = wolfSSL_sk_X509_value(store->certs, i);
if (wolfSSL_sk_X509_push(cert_stack, x509) > 0) {
store->numAdded++;

/* up x509 reference count since now store->certs points to it and
* cert_stack (which later gets passed off to a new obj and free'd)
*/
if (wolfSSL_X509_up_ref(x509) != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("wolfSSL_X509_up_ref error");
goto err_cleanup;
}
}
}
/* Do not modify stack until after we guarantee success to
Expand All @@ -1879,11 +1887,6 @@ WOLF_STACK_OF(WOLFSSL_X509_OBJECT)* wolfSSL_X509_STORE_get0_objects(
wolfSSL_X509_OBJECT_free(obj);
goto err_cleanup;
}
if (wolfSSL_X509_up_ref(x509) != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("wolfSSL_X509_up_ref error");
wolfSSL_X509_OBJECT_free(obj);
goto err_cleanup;
}
obj->type = WOLFSSL_X509_LU_X509;
obj->data.x509 = x509;
}
Expand Down Expand Up @@ -1918,10 +1921,7 @@ WOLF_STACK_OF(WOLFSSL_X509_OBJECT)* wolfSSL_X509_STORE_get0_objects(
if (ret != NULL)
X509StoreFreeObjList(store, ret);
if (cert_stack != NULL) {
while (store->numAdded > 0) {
wolfSSL_sk_X509_pop(cert_stack);
store->numAdded--;
}
store->numAdded = 0;
wolfSSL_sk_X509_pop_free(cert_stack, NULL);
}
return NULL;
Expand Down

0 comments on commit 1d09018

Please sign in to comment.