-
Notifications
You must be signed in to change notification settings - Fork 1k
Remove carry over of old buffers/sizes in EVP and X509 ext functions. #11021
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
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 |
|---|---|---|
|
|
@@ -9282,9 +9282,13 @@ static int PopulateRSAEvpPkeyDer(WOLFSSL_EVP_PKEY *pkey) | |
| #ifdef WOLFSSL_NO_REALLOC | ||
| derBuf = (byte*)XMALLOC((size_t)derSz, pkey->heap, DYNAMIC_TYPE_DER); | ||
| if (derBuf != NULL) { | ||
| XMEMCPY(derBuf, pkey->pkey.ptr, (size_t)pkey->pkey_sz); | ||
| XFREE(pkey->pkey.ptr, pkey->heap, DYNAMIC_TYPE_DER); | ||
| pkey->pkey.ptr = NULL; | ||
| /* Don't carry the cached DER over: the whole buffer is re-serialized | ||
| * below, and pkey_sz describes the previous key, which may be longer | ||
| * than derSz. */ | ||
| if (pkey->pkey.ptr != NULL) { | ||
| XFREE(pkey->pkey.ptr, pkey->heap, DYNAMIC_TYPE_DER); | ||
| pkey->pkey.ptr = NULL; | ||
| } | ||
| } | ||
| #else | ||
| derBuf = (byte*)XREALLOC(pkey->pkey.ptr, (size_t)derSz, | ||
|
|
@@ -9297,6 +9301,9 @@ static int PopulateRSAEvpPkeyDer(WOLFSSL_EVP_PKEY *pkey) | |
|
|
||
| /* Old pointer is invalid from this point on */ | ||
| pkey->pkey.ptr = (char*)derBuf; | ||
| /* pkey_sz still describes the old buffer; clear it so an error below | ||
| * cannot leave a length that overruns the new one. */ | ||
| pkey->pkey_sz = 0; | ||
|
|
||
| if (rsa->type == RSA_PRIVATE) { | ||
| ret = wc_RsaKeyToDer(rsa, derBuf, (word32)derSz); | ||
|
|
@@ -9840,25 +9847,17 @@ static int ECC_populate_EVP_PKEY(WOLFSSL_EVP_PKEY* pkey, WOLFSSL_EC_KEY *key) | |
| } | ||
| else if (ecc->type == ECC_PUBLICKEY) { | ||
|
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. 🟠 [Medium] ECC_populate_EVP_PKEY now keeps the previous key's cached DER on the serialization error path The rewritten Fix: Free and NULL |
||
| if ((derSz = wc_EccPublicKeyDerSize(ecc, 1)) > 0) { | ||
| #ifdef WOLFSSL_NO_REALLOC | ||
| derBuf = (byte*)XMALLOC((size_t)derSz, pkey->heap, DYNAMIC_TYPE_OPENSSL); | ||
| if (derBuf != NULL) { | ||
| XMEMCPY(derBuf, pkey->pkey.ptr, (size_t)pkey->pkey_sz); | ||
| XFREE(pkey->pkey.ptr, pkey->heap, DYNAMIC_TYPE_OPENSSL); | ||
| pkey->pkey.ptr = NULL; | ||
| } | ||
| #else | ||
| derBuf = (byte*)XREALLOC(pkey->pkey.ptr, (size_t)derSz, pkey->heap, | ||
| DYNAMIC_TYPE_OPENSSL); | ||
| #endif | ||
| derBuf = (byte*)XMALLOC((size_t)derSz, pkey->heap, | ||
| DYNAMIC_TYPE_OPENSSL); | ||
| if (derBuf != NULL) { | ||
| pkey->pkey.ptr = (char*)derBuf; | ||
| if ((derSz = wc_EccPublicKeyToDer(ecc, derBuf, (word32)derSz, | ||
| 1)) < 0) { | ||
| XFREE(derBuf, pkey->heap, DYNAMIC_TYPE_OPENSSL); | ||
| derBuf = NULL; | ||
| pkey->pkey.ptr = NULL; | ||
| pkey->pkey_sz = 0; | ||
| } | ||
| else { | ||
| XFREE(pkey->pkey.ptr, pkey->heap, DYNAMIC_TYPE_OPENSSL); | ||
| pkey->pkey.ptr = (char*)derBuf; | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 [Low] New test certificate has no generation recipe alongside the other cert-ext- certs*
Every other
certs/test/cert-ext-*artifact is produced bycerts/test/gen-ext-certs.shfrom a committed.cfg.cert-ext-oid-collide.deris committed as an opaque blob with no recipe;catalog.txtdocuments what it is (a 4-byte OID that hashes to the prime256v1 NID, invalid signature, parse-only) but not how to rebuild it. Ifwc_oid_sum()ever changes, no one can regenerate a colliding OID without redoing the analysis. (The certificate itself is fine for the test:wolfSSL_X509_load_certificate_file()parses withNO_VERIFY, so neither the bogus signature nor the 2029 notAfter matters.)Fix: Add a generation recipe or document how the colliding OID was derived so the artifact is reproducible.