From da9dc821e44a5cabe8d902c87255cfcfd91cc3a2 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Fri, 6 Mar 2026 12:03:36 +0100 Subject: [PATCH 1/2] wolfSSL_ASN1_item_i2d: simplify buf cleanup F-25 --- src/ssl_asn1.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ssl_asn1.c b/src/ssl_asn1.c index a53c5398b71..1b8cfda1c39 100644 --- a/src/ssl_asn1.c +++ b/src/ssl_asn1.c @@ -395,7 +395,6 @@ int wolfSSL_ASN1_item_i2d(const void* obj, byte** dest, { int ret = 1; int len = 0; - byte* buf = NULL; WOLFSSL_ENTER("wolfSSL_ASN1_item_i2d"); @@ -408,6 +407,7 @@ int wolfSSL_ASN1_item_i2d(const void* obj, byte** dest, ret = 0; if ((ret == 1) && (dest != NULL)) { + byte* buf = NULL; if (*dest == NULL) { buf = (byte*)XMALLOC((size_t)len, NULL, DYNAMIC_TYPE_ASN1); if (buf == NULL) @@ -428,11 +428,11 @@ int wolfSSL_ASN1_item_i2d(const void* obj, byte** dest, else *dest += len; } + if (*dest == NULL) + XFREE(buf, NULL, DYNAMIC_TYPE_ASN1); } if (ret == 0) { - if (*dest == NULL) - XFREE(buf, NULL, DYNAMIC_TYPE_ASN1); len = WOLFSSL_FATAL_ERROR; } WOLFSSL_LEAVE("wolfSSL_ASN1_item_i2d", len); From 3c06c2231429979fe26fb1b45b211cda3f266d82 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Fri, 6 Mar 2026 18:01:02 +0100 Subject: [PATCH 2/2] Make sure only free'd on error --- src/ssl_asn1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ssl_asn1.c b/src/ssl_asn1.c index 1b8cfda1c39..29aa52f9bcc 100644 --- a/src/ssl_asn1.c +++ b/src/ssl_asn1.c @@ -428,7 +428,7 @@ int wolfSSL_ASN1_item_i2d(const void* obj, byte** dest, else *dest += len; } - if (*dest == NULL) + if (ret == 0 && *dest == NULL) XFREE(buf, NULL, DYNAMIC_TYPE_ASN1); }