-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix multiple reported issues. #11009
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
base: master
Are you sure you want to change the base?
Changes from all commits
14a44c4
3e4da32
1a9160e
5ef4de7
07b700f
0e1e665
a07d5c6
99ede17
26a81ea
4017b71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -858,7 +858,6 @@ int wolfSSL_X509_verify_cert(WOLFSSL_X509_STORE_CTX* ctx) | |
| { | ||
| int ret = WC_NO_ERR_TRACE(WOLFSSL_FAILURE); | ||
| int done = 0; | ||
| int added = 0; | ||
| int i = 0; | ||
| int numFailedCerts = 0; | ||
| int depth = 0; | ||
|
|
@@ -997,11 +996,8 @@ int wolfSSL_X509_verify_cert(WOLFSSL_X509_STORE_CTX* ctx) | |
| &depth, origDepth); | ||
| continue; | ||
| } | ||
| added = 1; | ||
| ret = X509StoreVerifyCert(ctx); | ||
| if (ret != WOLFSSL_SUCCESS) { | ||
| if ((origDepth - depth) <= 1) | ||
| added = 0; | ||
| X509VerifyCertSetupRetry(ctx, certs, failedCerts, | ||
| &depth, origDepth); | ||
| continue; | ||
|
|
@@ -1023,21 +1019,14 @@ int wolfSSL_X509_verify_cert(WOLFSSL_X509_STORE_CTX* ctx) | |
| != WOLFSSL_SUCCESS) { | ||
| /* Could not guarantee the temporary intermediates were | ||
| * dropped; fail closed rather than risk verifying the current | ||
| * certificate against one. Leave `added` set: they are still | ||
| * loaded, so the exit cleanup makes a final attempt to drop | ||
| * them. */ | ||
| * certificate against one. */ | ||
|
kareem-wolfssl marked this conversation as resolved.
|
||
| ret = WOLFSSL_FATAL_ERROR; | ||
| goto exit; | ||
| } | ||
| added = 0; | ||
| ret = X509StoreVerifyCert(ctx); | ||
| if (ret != WOLFSSL_SUCCESS) { | ||
| /* WOLFSSL_PARTIAL_CHAIN may only terminate the chain at a | ||
| * certificate the caller actually trusts. The previous | ||
| * "added == 1" guard merely confirmed that some untrusted | ||
| * intermediate had been temporarily loaded into the | ||
| * CertManager during chain building, which would accept | ||
| * chains that never reach a trust anchor. Verify that | ||
| * certificate the caller actually trusts, so verify that | ||
| * ctx->current_cert is itself in the original trust set. */ | ||
| if (((ctx->flags & WOLFSSL_PARTIAL_CHAIN) || | ||
| (ctx->store->param != NULL && | ||
|
|
@@ -1149,11 +1138,17 @@ int wolfSSL_X509_verify_cert(WOLFSSL_X509_STORE_CTX* ctx) | |
| } | ||
| } | ||
| } | ||
| /* Remove intermediates that were added to CM */ | ||
| /* Remove intermediates that were added to CM. Unconditional: anything left | ||
| * resident anchors verification for every other user of this CM. */ | ||
| if (ctx != NULL) { | ||
| if (ctx->store != NULL) { | ||
| if (added == 1) { | ||
| wolfSSL_CertManagerUnloadTempIntermediateCerts(ctx->store->cm); | ||
| if (wolfSSL_CertManagerUnloadTempIntermediateCerts(ctx->store->cm) | ||
| != WOLFSSL_SUCCESS) { | ||
| WOLFSSL_MSG("Failed to unload temporary intermediates"); | ||
| /* Any left resident would anchor later verifications, so do | ||
| * not report success. */ | ||
| if (ret == WOLFSSL_SUCCESS) | ||
| ret = WOLFSSL_FAILURE; | ||
| } | ||
| } | ||
| if (orig != NULL) { | ||
|
|
@@ -1777,13 +1772,15 @@ static void X509StoreFreeObjList(WOLFSSL_X509_STORE* store, | |
| * the numAdded to the store >= is used when comparing to 0. */ | ||
| i = wolfSSL_sk_X509_OBJECT_num(objs) - 1; | ||
| while (cnt > 0 && i >= 0) { | ||
| /* The inner X509 is owned by somebody else, NULL out the reference */ | ||
| obj = (WOLFSSL_X509_OBJECT *)wolfSSL_sk_X509_OBJECT_value(objs, i); | ||
| if (obj != NULL) { | ||
| /* Only certificates are borrowed, so only they consume numAdded. The | ||
| * CRL object appended after them must not shift this window. */ | ||
| if (obj != NULL && obj->type == WOLFSSL_X509_LU_X509) { | ||
| /* The inner X509 is owned by somebody else, NULL out the ref */ | ||
| obj->type = (WOLFSSL_X509_LOOKUP_TYPE)0; | ||
| obj->data.ptr = NULL; | ||
| cnt--; | ||
| } | ||
| cnt--; | ||
| i--; | ||
| } | ||
|
Comment on lines
1773
to
1785
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
|
@@ -2522,6 +2519,9 @@ WOLF_STACK_OF(WOLFSSL_X509_OBJECT)* wolfSSL_X509_STORE_get0_objects( | |
| { | ||
| WOLFSSL_STACK* ret = NULL; | ||
| WOLFSSL_STACK* cert_stack = NULL; | ||
| /* Set once the certificates have been handed over to "ret". Until then | ||
| * cert_stack still owns them and the error path must not free them. */ | ||
| byte certsOwned = 0; | ||
| #if ((defined(WOLFSSL_SIGNER_DER_CERT) && !defined(NO_FILESYSTEM)) || \ | ||
| (defined(HAVE_CRL))) | ||
| WOLFSSL_X509_OBJECT* obj = NULL; | ||
|
|
@@ -2595,6 +2595,7 @@ WOLF_STACK_OF(WOLFSSL_X509_OBJECT)* wolfSSL_X509_STORE_get0_objects( | |
| while (wolfSSL_sk_X509_num(cert_stack) > 0) { | ||
| wolfSSL_sk_X509_pop(cert_stack); | ||
| } | ||
| certsOwned = 1; | ||
| #endif | ||
|
|
||
| #ifdef HAVE_CRL | ||
|
|
@@ -2625,8 +2626,28 @@ WOLF_STACK_OF(WOLFSSL_X509_OBJECT)* wolfSSL_X509_STORE_get0_objects( | |
| store->objs = ret; | ||
| return ret; | ||
| err_cleanup: | ||
| if (ret != NULL) | ||
| X509StoreFreeObjList(store, ret); | ||
| if (ret != NULL) { | ||
| if (certsOwned) { | ||
| X509StoreFreeObjList(store, ret); | ||
| } | ||
| else { | ||
| /* cert_stack still owns these certificates. pop_free() below runs | ||
| * wolfSSL_X509_OBJECT_free() on each entry, which frees the inner | ||
| * X509, so clear the references or they are freed twice. */ | ||
| int j; | ||
| WOLFSSL_X509_OBJECT* cur; | ||
|
|
||
| for (j = 0; j < wolfSSL_sk_X509_OBJECT_num(ret); j++) { | ||
| cur = (WOLFSSL_X509_OBJECT*)wolfSSL_sk_X509_OBJECT_value(ret, | ||
| j); | ||
| if (cur != NULL) { | ||
| cur->type = (WOLFSSL_X509_LOOKUP_TYPE)0; | ||
| cur->data.ptr = NULL; | ||
| } | ||
| } | ||
| wolfSSL_sk_X509_OBJECT_pop_free(ret, NULL); | ||
| } | ||
| } | ||
|
Comment on lines
2628
to
+2650
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, just increase the reference counter when placing objects inside the stack and simplify the cleanup logic to always call the free. |
||
| if (cert_stack != NULL) { | ||
| while (store->numAdded > 0) { | ||
| wolfSSL_sk_X509_pop(cert_stack); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.