]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
lms: free previous encoded public key in ossl_lms_pubkey_decode
authorrootvector2 <dxbnaveed.k@gmail.com>
Sun, 31 May 2026 17:22:26 +0000 (22:52 +0530)
committerTomas Mraz <tomas@openssl.foundation>
Thu, 25 Jun 2026 16:58:41 +0000 (18:58 +0200)
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)

crypto/lms/lms_pubkey_decode.c

index 8c2ee0ff5e436241b06a0a6697632e8560de4e24..29ca1d44af8268cb2e0c4ee3e5a85e79f98728bb 100644 (file)
@@ -95,7 +95,7 @@ int ossl_lms_pubkey_decode(const unsigned char *pub, size_t publen,
 {
     LMS_PUB_KEY *pkey = &lmskey->pub;
 
-    if (pkey->encoded != NULL && pkey->encodedlen != publen) {
+    if (pkey->encoded != NULL) {
         OPENSSL_free(pkey->encoded);
         pkey->encodedlen = 0;
     }
@@ -110,6 +110,7 @@ int ossl_lms_pubkey_decode(const unsigned char *pub, size_t publen,
 err:
     OPENSSL_free(pkey->encoded);
     pkey->encoded = NULL;
+    pkey->encodedlen = 0;
     return 0;
 }