From 9c7b58656541e8d31876d7ccd2cd38140b8ffb79 Mon Sep 17 00:00:00 2001 From: Reda Chouk Date: Thu, 8 Jan 2026 19:57:24 +0100 Subject: [PATCH] Increment signedAttribsCount with the right number of attributes it encoded --- wolfcrypt/src/pkcs7.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wolfcrypt/src/pkcs7.c b/wolfcrypt/src/pkcs7.c index 9c99f8cf5..677441e42 100644 --- a/wolfcrypt/src/pkcs7.c +++ b/wolfcrypt/src/pkcs7.c @@ -2074,6 +2074,11 @@ static int wc_PKCS7_BuildSignedAttributes(wc_PKCS7* pkcs7, ESD* esd, /* add custom signed attributes if set */ if (pkcs7->signedAttribsSz > 0 && pkcs7->signedAttribs != NULL) { + word32 availableSpace = MAX_SIGNED_ATTRIBS_SZ - atrIdx; + + if (pkcs7->signedAttribsSz > availableSpace) + return BUFFER_E; + esd->signedAttribsCount += pkcs7->signedAttribsSz; esd->signedAttribsSz += (word32)EncodeAttributes( &esd->signedAttribs[atrIdx], (int)esd->signedAttribsCount,