ossl_lms_pubkey_decode() only freed pkey->encoded when the new public key
had a different length, so re-decoding a same-length key on the documented
repeated-call path overwrote the old buffer without freeing it. Always free
the existing buffer first.
Also clear pkey->encodedlen on the error path so a failed decode leaves the
key in a consistent state instead of keeping a stale length.
CLA: trivial
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
Reviewed-by: Bob Beck <beck@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.foundation>
MergeDate: Thu Jun 25 16:58:46 2026
(Merged from https://github.com/openssl/openssl/pull/31345)
{
LMS_PUB_KEY *pkey = &lmskey->pub;
- if (pkey->encoded != NULL && pkey->encodedlen != publen) {
+ if (pkey->encoded != NULL) {
OPENSSL_free(pkey->encoded);
pkey->encodedlen = 0;
}
err:
OPENSSL_free(pkey->encoded);
pkey->encoded = NULL;
+ pkey->encodedlen = 0;
return 0;
}