]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Patch TODO: Always release decoded BER, even on error
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 9 May 2024 23:48:42 +0000 (17:48 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 9 May 2024 23:48:42 +0000 (17:48 -0600)
src/asn1/asn1c/CMSAttribute.c
src/asn1/asn1c/ContentInfo.c
src/asn1/asn1c/EncapsulatedContentInfo.c
src/print_file.c

index b016cb657e4ca3c19d16f8304b0f38cb2a9a0066..91b23f1c912cb1499b6e7a083e82b578a8f34804 100644 (file)
@@ -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;
index 8522f913fad2382b9f5121f1dd60d426c334cd6a..1f226193b991a3d0d24c427b539dfa02247a2847 100644 (file)
@@ -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 *
index e181787fb1850cc2ad68806b12b19b7e937f0500..7c5e851cc02c758894412626eba0096de3c14411 100644 (file)
@@ -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 *
index c5d92e619b1c8117895b0c3f307b5a5a765072a9..c16aff73b8498ebbc3be41d0a1876a5a983e80a5 100644 (file)
@@ -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 *