Skip to content

Remove carry over of old buffers/sizes in EVP and X509 ext functions. - #11021

Open
kareem-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
kareem-wolfssl:zd22223
Open

Remove carry over of old buffers/sizes in EVP and X509 ext functions.#11021
kareem-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
kareem-wolfssl:zd22223

Conversation

@kareem-wolfssl

Copy link
Copy Markdown
Contributor

Description

Fixes zd#22223

Testing

Built in tests, added tests, provided reproducer

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

Thanks to Kushal Khemka & Mayank Jangid (OpenSec Intelligence) for the report.
@kareem-wolfssl kareem-wolfssl self-assigned this Jul 30, 2026
Copilot AI review requested due to automatic review settings July 30, 2026 22:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.der fixture 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 thread src/x509.c
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 thread wolfcrypt/src/evp.c
Comment on lines 9288 to 9289
XFREE(pkey->pkey.ptr, pkey->heap, DYNAMIC_TYPE_DER);
pkey->pkey.ptr = NULL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants