From 3df1b443912de720cf34a03b164f85673c12e7c9 Mon Sep 17 00:00:00 2001 From: Alberto Leiva Popper Date: Thu, 9 May 2024 17:48:42 -0600 Subject: [PATCH] Patch TODO: Always release decoded BER, even on error --- src/asn1/asn1c/CMSAttribute.c | 4 +--- src/asn1/asn1c/ContentInfo.c | 8 +++----- src/asn1/asn1c/EncapsulatedContentInfo.c | 8 +++----- src/print_file.c | 7 +++++-- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/asn1/asn1c/CMSAttribute.c b/src/asn1/asn1c/CMSAttribute.c index b016cb65..91b23f1c 100644 --- a/src/asn1/asn1c/CMSAttribute.c +++ b/src/asn1/asn1c/CMSAttribute.c @@ -20,10 +20,8 @@ attr2json(asn_TYPE_descriptor_t const *td, CMSAttributeValue_t const *ber) attr = NULL; rval = ber_decode(NULL, td, &attr, ber->buf, ber->size); - if (rval.code != RC_OK) - return NULL; /* TODO release attr? */ - json = td->op->json_encoder(td, attr); + json = (rval.code == RC_OK) ? td->op->json_encoder(td, attr) : NULL; ASN_STRUCT_FREE(*td, attr); return json; diff --git a/src/asn1/asn1c/ContentInfo.c b/src/asn1/asn1c/ContentInfo.c index 8522f913..1f226193 100644 --- a/src/asn1/asn1c/ContentInfo.c +++ b/src/asn1/asn1c/ContentInfo.c @@ -14,17 +14,15 @@ content2json(const asn_TYPE_descriptor_t *td, ANY_t const *ber) { void *decoded; asn_dec_rval_t rval; - json_t *content; + json_t *json; decoded = NULL; rval = ber_decode(NULL, td, &decoded, ber->buf, ber->size); - if (rval.code != RC_OK) - return NULL; - content = td->op->json_encoder(td, decoded); + json = (rval.code == RC_OK) ? td->op->json_encoder(td, decoded) : NULL; ASN_STRUCT_FREE(*td, decoded); - return content; + return json; } json_t * diff --git a/src/asn1/asn1c/EncapsulatedContentInfo.c b/src/asn1/asn1c/EncapsulatedContentInfo.c index e181787f..7c5e851c 100644 --- a/src/asn1/asn1c/EncapsulatedContentInfo.c +++ b/src/asn1/asn1c/EncapsulatedContentInfo.c @@ -15,17 +15,15 @@ econtent2json(asn_TYPE_descriptor_t const *td, OCTET_STRING_t *eContent) { void *decoded; asn_dec_rval_t rval; - json_t *content; + json_t *json; decoded = NULL; rval = ber_decode(NULL, td, &decoded, eContent->buf, eContent->size); - if (rval.code != RC_OK) - return NULL; - content = td->op->json_encoder(td, decoded); + json = (rval.code == RC_OK) ? td->op->json_encoder(td, decoded) : NULL; ASN_STRUCT_FREE(*td, decoded); - return content; + return json; } json_t * diff --git a/src/print_file.c b/src/print_file.c index c5d92e61..c16aff73 100644 --- a/src/print_file.c +++ b/src/print_file.c @@ -111,7 +111,7 @@ bio2ci(BIO *bio) do { if (!BIO_read_ex(bio, buffer, BUFFER_SIZE, &consumed)) { op_crypto_err("IO error."); - return NULL; + goto fail; } res = ber_decode(NULL, &asn_DEF_ContentInfo, (void **)&ci, @@ -133,9 +133,12 @@ bio2ci(BIO *bio) case RC_FAIL: pr_op_err("Unsuccessful parse."); - return NULL; + goto fail; } } while (true); + +fail: ASN_STRUCT_FREE(asn_DEF_ContentInfo, ci); + return NULL; } static json_t * -- 2.47.3