Remove carry over of old buffers/sizes in EVP and X509 ext functions. - #11021
Open
kareem-wolfssl wants to merge 1 commit into
Open
Remove carry over of old buffers/sizes in EVP and X509 ext functions.#11021kareem-wolfssl wants to merge 1 commit into
kareem-wolfssl wants to merge 1 commit into
Conversation
Thanks to Kushal Khemka & Mayank Jangid (OpenSec Intelligence) for the report.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes issues where cached buffers/lengths from prior operations could be carried over in EVP_PKEY DER caching and X509 extension OID handling, potentially leading to incorrect sizing/overreads. It also adds targeted regression tests and a new certificate fixture to cover the reported edge cases (zd#22223).
Changes:
- EVP: stop carrying forward prior cached DER data/length when repopulating RSA/ECC EVP_PKEY DER buffers.
- X509 ext: stop carrying forward the canonical OID buffer when the extension’s OID in the certificate is shorter than the mapped NID’s canonical OID.
- Add regression tests plus a new
cert-ext-oid-collide.derfixture and catalog entry.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| wolfcrypt/src/evp.c | Clears/stops reusing stale cached DER buffers/sizes when repopulating EVP_PKEY DER for RSA/ECC. |
| src/x509.c | Avoids copying/reusing old ASN1_OBJECT OID buffers when rebuilding extension OIDs from the certificate. |
| tests/api/test_ossl_x509_ext.h | Registers new X509 extension regression test. |
| tests/api/test_ossl_x509_ext.c | Adds regression test ensuring returned extension OIDs reflect the certificate’s OID encoding/size. |
| tests/api/test_evp_pkey.h | Registers new EVP_PKEY DER “shrink” regression test. |
| tests/api/test_evp_pkey.c | Adds regression coverage for DER cache resizing across RSA/PKCS#8/ECC public-only scenarios. |
| certs/test/include.am | Distributes the new DER fixture in test artifacts. |
| certs/test/catalog.txt | Documents the new fixture and its purpose. |
Comments suppressed due to low confidence (1)
wolfcrypt/src/evp.c:9859
- XFREE(pkey->pkey.ptr, ...) is unconditionally called here, unlike other branches in ECC_populate_EVP_PKEY which guard the free with a NULL check. Adding the guard improves portability in case the underlying allocator does not accept NULL frees.
else {
XFREE(pkey->pkey.ptr, pkey->heap, DYNAMIC_TYPE_OPENSSL);
pkey->pkey.ptr = (char*)derBuf;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1121
to
1124
| * which may be longer than the OID in the certificate. */ | ||
| tmp = (byte*)XMALLOC(objSz, NULL, DYNAMIC_TYPE_ASN1); | ||
| if (tmp != NULL && ext->obj->obj != NULL) { | ||
| XMEMCPY(tmp, ext->obj->obj, ext->obj->objSz); | ||
| XFREE((byte*)ext->obj->obj, NULL, DYNAMIC_TYPE_ASN1); | ||
| } | ||
| else if (tmp == NULL) { | ||
| XFREE((byte*)ext->obj->obj, NULL, DYNAMIC_TYPE_ASN1); | ||
| } | ||
| XFREE((byte*)ext->obj->obj, NULL, DYNAMIC_TYPE_ASN1); | ||
| ext->obj->obj = tmp; |
Comment on lines
9288
to
9289
| XFREE(pkey->pkey.ptr, pkey->heap, DYNAMIC_TYPE_DER); | ||
| pkey->pkey.ptr = NULL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes zd#22223
Testing
Built in tests, added tests, provided reproducer
Checklist